我正在使用ggplot2在运行elcapitan的mac上创建一个Forest Plot。 背景中有微弱的垂直线 - 这些不是网格线。这是“主题”设置:
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")
)
关于如何摆脱这些灰线的任何想法? 是一个使用这个板和R和ggplot2--的新手 很高兴加载样本数据和我的代码 - 但不确定这里是否有用。
情节截图:
更新以回应Diego的代码问题:
此代码基于Matt统计数据和代码的代码 - https://mcfromnz.wordpress.com/2012/11/06/forest-plots-in-r-ggplot-with-side-table/ - 但我找不到他原始代码的链接。
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()
答案 0 :(得分:1)
一个可重复性最小的示例比一系列有趣的格式化和排列代码更有用。
library(ggplot2)
library(ggthemes)
library(gridExtra)
gg <- ggplot()
gg <- gg + geom_text(data=data.frame(x=1, y=1, label="label"),
aes(x, y, label=label))
gg <- gg + theme_map()
gg_left <- gg
gg <- ggplot()
gg <- gg + geom_point(data=mtcars, aes(mpg, wt))
gg <- gg + theme_bw()
gg_right <- gg
grid.arrange(gg_left, gg_right, ncol=2)
正如你所看到的,我在Mac上,甚至离开了舒适的RStudio,在R.app中测试产生一个纯粹的石英窗口&#34;。
我正在努力重新组织您的代码,让核心图表正常工作,然后应用您想要的主题与依赖cut&amp; amp;粘贴代码。