0

How can I plot a dotchart like lattice's dotchart in ggplot2 that has thicker grid lines and only horizontal grid lines (ie remove the vertical grid lines), kind of like this:

https://i.stack.imgur.com/gBtM2.png

Except make the horizontal lines even bolder so that they are more visible.

Is there a way to do this in ggplot2?

  • 2
    What have you tried? And why do you want this in `ggplot2` if `lattice` already do what you want? – agstudy Mar 16 '13 at 18:48
  • @agstudy, for the 2nd part of the question, I'd just say, I'd like to know how to do it.. :) – Arun Mar 16 '13 at 19:05
  • @Arun it is a good reason if you show you can do it with `lattice` (at least). – agstudy Mar 16 '13 at 19:09
  • Plus it gives us an example to workfrom. Right now we have to make up a dataset. – Tyler Rinker Mar 16 '13 at 19:17
  • 1
    Did you look at this? http://stackoverflow.com/questions/2684966/how-can-i-suppress-the-vertical-gridlines-in-a-ggplot2-plot-while-retaining-the or more relevantly http://stackoverflow.com/questions/2678141/how-can-i-suppress-the-vertical-gridlines-in-a-ggplot2-plot/8992102#8992102 – Ben Bolker Mar 16 '13 at 19:19
  • @TylerRinker, I agree that the OP should post data to work with. – Arun Mar 16 '13 at 19:24

1 Answers1

5

Some sample data to work with.

df<-data.frame(nam=rep(c("A","B","C","D","E"),times=3),
  val=runif(15,0,1),type=rep(c("TypA","TypB","TypC"),each=5))
df<-rbind(df,df,df)
df$num.lev<-rep(c(10,20,30),each=15)

To change appearance of gridlines panel.grid.major and panel.grid.minor can be used inside theme(). With panel.margin= you can achieve that all facets are plotted close together.

library(ggplot2)
library(grid)
ggplot(df,aes(val,nam))+geom_point(size=3,colour="blue")+facet_grid(num.lev~type)+
  scale_x_continuous(breaks=c(0,0.2,0.4,0.6,0.8))+
  theme(panel.margin=unit(0,"cm"),
        panel.border=element_rect(colour="black",fill=NA,size=1.2),
        strip.background=element_rect(colour="black",size=1.2),
        panel.grid.major.x=element_blank(),
        panel.grid.minor.x=element_blank(),
        panel.grid.major.y=element_line(size=1.5,colour="grey88"),
        panel.background=element_rect(fill="white"))

enter image description here

Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201