I am using ggplot2 to create a Forest Plot on a mac running elcapitan. There are faint vertical lines in the background-- these are not grid lines. This is the "theme" setting:
theme_set(theme_bw())
theme_update(
axis.line = element_line(colour = "black"),
axis.line.y=element_line(colour="white"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
plot.margin = unit(c(0,0,0,0), "lines")
)
Any ideas on how to get rid of these grey lines? Am a newbie at using this board and R and ggplot2-- Happy to load sample data and my code-- but not sure if useful here.
Screenshot of plot:
UPDATE in response to Diego's question for the code:
This code was based on code from Matt's Stats and stuff -- https://mcfromnz.wordpress.com/2012/11/06/forest-plots-in-r-ggplot-with-side-table/ -- but I can't find the link to his original code.
theme_set(theme_bw())
theme_update(
axis.line = element_line(colour = "black"),
axis.line.y=element_line(colour="white"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
plot.margin = unit(c(0,0,0,0), "lines")
)
pD<- ggplot(datD,aes(cen,rev(author2))) +
geom_point(aes(fill = summary), size=1.7,shape=23,colour="black") +
geom_errorbarh(
aes(xmax = datD$high, xmin = datD$low, colour=summary),
height = 0.3, size=0.25) +
scale_x_continuous(
breaks = seq(0,1,.1), labels = seq(0,100,10)) +
labs(x="Risk, %", y="") +
theme(axis.text.x=element_text(size=2))+geom_text(aes(0, author2), label=(paste(rev(datD$author2),rev(datD$risk))), hjust=0, size=ifelse(rev(datD$author2)=="Heterogeneity (95% CI)",2,0), fontface="bold")
p2D<-pD+
theme(legend.position = "none",
axis.text.x = element_text(size=6),
axis.title = element_text(size=6,face="italic")) +
guides(size = FALSE) +
geom_hline(aes(yintercept=c((length(datD$authorREF2)-0.5))))
#Left hand side will be author_yr, Events, Participants
#V0 indicates how many y-axis datapoints there willbe
#V05 spaces out the table columns on the x-axis
#V1 is a vector of all the columns that will be in the table
lab_left1D<-data.frame(
V0 = factor(
c(as.factor(1:length(datD$authorREF2))),
levels=c(as.factor(length(datD$authorREF2):1))
),
V05 = rep(
c(1,1.25,1.5,1.7),
each=length(datD$authorREF2)
),
V1 = c(c(as.character(datD$authorREF2)),
c(as.character(datD$Events)),
c(as.character(datD$patients)),
c(as.character(datD$risk))))
data_table_left1D<-ggplot(lab_left1D,
aes(x = V05, y = V0,
label = format(V1, nsmall = 1))) +
geom_text(
aes(fontface =
ifelse(
V0==as.character((length(datD$authorREF2)-1)),'bold.italic',
ifelse(V0=='1','bold',
ifelse(V0==as.character
(length(datD$authorREF2)),'italic','plain')))),
size = ifelse(
lab_left1D$V0==as.character(length(datD$authorREF2)),0,2), hjust=0, vjust=1.3) + theme_bw() +
theme(panel.grid.major = element_blank(),
legend.position = "none",
panel.border = element_blank(),
#axis.line = element_line(colour = "black"),
axis.text.x = element_text(colour="white"),#element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_line(colour="white"),#element_blank(),
plot.margin = unit(c(0.5,0,0,0), "lines")) +
labs(x="",y="") +
coord_cartesian(xlim=c(1,2.5))
grid.arrange(data_table_left1D, p2D,widths=c(5,3))
dev.off()