I have a dataframe with 2 columns: date and var1.
Now I want to plot these 2 variables in a ggplot and add small lines with geom_rug().
df<-tibble(date=lubridate::today() -0:14,
var1= c(1,2.5,NA,3,NA,6.5,1,NA,3,2,NA,7,3,NA,1))
df%>%ggplot(aes(x=date,y=var1))+
geom_point()+
geom_rug(sides = "tr",outside = T) +
# Need to turn clipping off if rug is outside plot area
coord_cartesian(clip = "off")
And here is my plot:
But my problem is that the small lines for var1 are on the left side. I want to have them on the top.
With the argument sides= you can change the disposition of the small lines, like here:
df%>%ggplot(aes(x=date,y=var1))+
geom_point()+
geom_rug(sides = "t",outside = T) +
# Need to turn clipping off if rug is outside plot area
coord_cartesian(clip = "off")
But in this example the small lines are representing the date and not the var1. (var1 has only 10 values, but there are 15 small lines)
Can someone help me, how can reverse the geom_rug-element and avoid this problem?


