4

I have an issue about to draw a trendline in between each panel of in facet_grid and want to label variable values as shown like this;

enter image description here

same as other varibles you can imagine. How can we do that ?

here is my df and ggplot code to create this density facet_grid without tracing lines

fidel <- rep(seq(-30,30,30),each=5)
resp <- replicate(3,c(sort(10^runif(5,-6,0),decreasing=TRUE), sort(10^runif(5,-4,0),decreasing=TRUE),sort(10^runif(5,-2,0),decreasing=TRUE)))
Wdd <- rep(seq(1:5),times=3)
df <-   data.frame(fidel,resp,Wdd)

library(reshape2)   #for wide to long format
df_new <- melt(df,id=c("fidel","Wdd"))  

ggplot(df_new, aes(x=value,fill=factor(Wdd)))+
  geom_density(alpha=.5,adjust=0.5)+
  scale_x_log10(breaks = c(1e-5,1e-3,1e-1,1),limits = c(1e-6,1))+
  scale_y_continuous(breaks=seq(0,1,0.2),limits=c(0,1))+
  facet_grid(fidel~Wdd,scales="free_x")+
  theme(legend.position = "top")
Alexander
  • 4,527
  • 5
  • 51
  • 98
  • Have you tried something for exampled based on this approach: http://stackoverflow.com/questions/31690007/ggplot-drawing-line-between-points-across-facets ? – lukeA Oct 12 '15 at 09:07
  • @lukeA i just checked that link. But it seems very complicated way. There should be a much elegant way I guess.. – Alexander Oct 12 '15 at 09:13
  • 4
    I guess not. :-) (So my 1st thought was: Better do it with InkScape in 3 Minutes, if it's a one time report, than getting too hack'ish with grid.) But let's see. – lukeA Oct 12 '15 at 09:15
  • @lukeA its not a one tıme report or homework. I just provide here three `varible` but in real data ı have 100 `varible`. So I need to automated plot for selected `varible` to plot trendline to find out how this variables scattered between grids. So inkscape solution wont work for me. – Alexander Oct 12 '15 at 09:18
  • 1
    As I said: trying to draw lines between facets probably is not worth the effort. Stay with just marking the points, which is relatively easy. – lukeA Oct 12 '15 at 12:14
  • @lukeA so how can I mark the points? with the link that you suggested? – Alexander Oct 12 '15 at 12:33
  • To annotate facets (e.g. with custom text and points), have a look here https://www.google.com/search?q=ggplot+annovate+facets – lukeA Oct 12 '15 at 12:51
  • Have you seen [this](http://stackoverflow.com/questions/32158374/draw-lines-between-two-different-grid-arranged-plots) gtable approach in the answer by baptiste? – RHA Oct 12 '15 at 13:47
  • at least can somebody answer with using reproducible `df` here? – Alexander Oct 13 '15 at 00:45
  • Easiest workaround might be not to use facetting along rows, but simply offset the data vertically – baptiste Oct 13 '15 at 02:58

0 Answers0