我对ggplot2很陌生,如果这篇文章太愚蠢,请原谅我。我使用以下代码绘制数据,但无法获得发布所需的样式。
在输出中,我需要:
一个传奇。在我的数据案例中,
opts(legend.position="top")
我不知道为什么之后什么都没有。而且我还想将图例拆分为 3 列,例如columns=3
inauto.key
of latticefill=c("white","grey20","grey70")
根据 factor使用灰色系统(例如,)对条形进行着色pl
,但似乎我无法更改样式scale_colour_manual
将 x 轴上的标签转为水平。
也许是y轴?但是,你觉得有必要吗?
顺便说一句,我不知道如何准备出版图,所以,非常欢迎任何建议!
library(ggplot2)
wt<-gl(3,4,108,labels=c("W30","W60","W90"))
pl<-gl(3,12,108,labels=c("P0","P1","P2"))
gp<-gl(3,36,108,labels=c("A","B","C"))
dat<-cbind(A=runif(108),B=runif(108,min=1,max=10),C=runif(108,min=100,max=200),D=runif(108,min=1000,max=1500))
dat.df<-data.frame(wt,pl,gp,dat)
dat.m<-melt(dat.df)
ggplot(dat.m,aes(x=wt,y=value,group=pl,facet=gp,fill=pl))+
stat_summary(fun.y=mean,geom="bar",size=2,position="dodge")+
stat_summary(fun.ymin=function(x)(mean(x)-sd(x)/sqrt(length(x))),geom="errorbar",
fun.ymax=function(x)(mean(x)+sd(x)/sqrt(length(x))),position="dodge")+
facet_grid(variable~facet,scale="free_y")+ opts(legend.position="top")+
scale_colour_manual(values = c("red", "blue", "green"))