library(data.table)
#> Warning: package 'data.table' was built under R version 3.5.3
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 3.5.3
#> Warning: package 'tibble' was built under R version 3.5.3
#> Warning: package 'tidyr' was built under R version 3.5.3
#> Warning: package 'readr' was built under R version 3.5.3
#> Warning: package 'purrr' was built under R version 3.5.3
#> Warning: package 'dplyr' was built under R version 3.5.3
#> Warning: package 'stringr' was built under R version 3.5.3
#> Warning: package 'forcats' was built under R version 3.5.3
sidc<-fread("http://sidc.be/silso/DATA/SN_d_tot_V2.0.csv",sep = ';')
colnames(sidc) <- c("Year","Month","Day", "Fdate","Spots", "Sd","Obs" ,"Defin" )
sidc$Ymd <- as.Date(paste(sidc$Year, sidc$Month, sidc$Day, sep = "-"))
sidc<-sidc[Year>=2014,]
## Plot columns print hoizontal with filter statement:
A <- sidc %>% filter(Spots >=21 & Spots <=130)
ggplot(data=A) + geom_col(aes(x=Ymd,y=Spots)) + ggtitle("Plot with filter statement")
## But print as expected with out filter statement:
ggplot(data=sidc,aes(x=Ymd,y=Spots)) + geom_col() + ggtitle("Plot without filter statment")
Created on 2019-12-08 by the reprex package (v0.3.0.9000)
And here is the top of my sessionInfo()
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Well, I spoke to soon, I updated to the lastest RStudio(1.2.5019) and building tidyverse from github but that didn't solve the problem. The problem maybe be with the "geom_col()" function, because when I use geom_point() or geom_line() the display the plot with the correct orientation ? Here's my setup:
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
library(tidyverse)
-- Attaching packages ----------------------------------
tidyverse 1.3.0.9000 --
v ggplot2 3.2.1.9000 v purrr 0.3.3
v tibble 2.1.3 v dplyr 0.8.3
v tidyr 1.0.0 v stringr 1.4.0
v readr 1.3.1 v forcats 0.4.0
-- Conflicts --------------------------
Can you make a Reprex out of your code? It will then be run in its own environment and you can post the exact inputs and outputs. In the post below, you just have to do the Your Final Reprex section.
A couple of notes: (1) I seems to only effect geom_col() feature, also It seems to only effect the Spots filed i.e If I "filter" on "Year: or "Ymd "the plot runs without error? and finally I have a linux box running R-3.4.4 and the plot runs fine. Here's some output for str() and sessionInfo().
This is happening because you are using the development version of ggplot2 which now supports horizontal column plots natively and automatically chooses the orientation, it seems like in this case is not giving the expected result so you would have to manually set it.