我使用ggplot2在運行elcapitan的mac上創建森林情節。 背景中有微弱的垂直線 - 這些不是網格線。這是「主題」設置:劇情灰色線條在劇情ggplot2 grid.arrange R Mac OSx石英背景
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-- 很高興加載示例數據和我的代碼 - 但不知道這裏是否有用。
截圖情節:響應於聖地亞哥的代碼問題
UPDATE:
此代碼是基於從馬特的統計代碼和東西 - 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()
它_sure_看起來像左邊的ggplot仍然有主要的網格線設置。如果發佈實際的代碼而不僅僅是主題位,我們將能夠真正地提供幫助。我們不知道你還可能在哪裏引入了主要網格線的可能性,以避免重新陷入其中。 – hrbrmstr
我不認爲它是一個網格線 - 我認爲它與R如何渲染石英成一體Mac - – HanzMoleman
我使用的是蘋果機,這是非常有趣的格式化代碼。不知道你以前是否見過[this](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example),但它有助於解釋如何在R中工作SO問答論壇的一面。 – hrbrmstr