使用新版ggplot2和scale,我无法弄清楚如何以科学计数法获得轴标签.例如:
x <- 1:4
y <- c(0, 0.0001, 0.0002, 0.0003)
dd <- data.frame(x, y)
ggplot(dd, aes(x, y)) + geom_point()
Run Code Online (Sandbox Code Playgroud)
给我

我想轴标签是0,5 x 10 ^ -5,1 x 10 ^ -4,1.5 x 10 ^ -4等.我无法弄清楚正确的组合scale_y_continuous()和math_format()(至少我认为那些是我需要的).
scale_y_log10()日志转换轴,我不想要.scale_y_continuous(label = math_format())只给我10 ^ 0,10 ^ 5e-5等等.我明白为什么后者给出了这个结果,但这不是我想要的.
我正在使用ggplot2_0.9.1和scales_0.2.1
我有一个包含csv文件的文件夹,每个文件有两列数据,例如:
0,red
15.657,red
0,red
0,red
4.429,red
687.172,green
136.758,green
15.189,red
0.152,red
23.539,red
0.348,red
0.17,blue
0.171,red
0,red
61.543,green
0.624,blue
0.259,red
338.714,green
787.223,green
1.511,red
0.422,red
9.08,orange
7.358,orange
25.848,orange
29.28,orange
Run Code Online (Sandbox Code Playgroud)
我使用以下R代码生成箱图:
files <- list.files(path="D:/Ubuntu/BoxPlots/test/", pattern=NULL, full.names=F, recursive=FALSE)
files.len<-length(files)
col_headings<-c("RPKM", "Lineage")
for (i in files){
i2<-paste(i,"png", sep=".")
boxplots<-read.csv(i, header=FALSE)
names(boxplots)<-col_headings
png(i2)
bplot<-ggplot(boxplots, aes(Lineage, RPKM)) + geom_boxplot(aes(fill=factor(Lineage))) + geom_point(aes(colour=factor(Lineage)))
print(bplot)
graphics.off()
}
Run Code Online (Sandbox Code Playgroud)
现在我想改变箱线图的颜色以匹配相应的x轴颜色标签.我还想更改x轴标签的名称,以及它们的顺序.有没有办法使用ggplot或qplot来做到这一点?
如何在ggplot2中更改x轴标签的名称?见下文:
ggbox <- ggplot(buffer, aes(SampledLUL, SOC)) + geom_boxplot()
ggbox <- ggbox + theme(axis.text.x=element_text(color = "black", size=11, angle=30, vjust=.8, hjust=0.8))
ggbox<- ggbox + labs(title = "Land cover Classes") + ylab("SOC (g C/m2/yr)") + xlab("Land cover classes")
Run Code Online (Sandbox Code Playgroud)
上面的代码创建了下图:

我希望能够对这些类的第一个字母(即Crop,而不是crop)进行首映.
我已经尝试了下面的代码,但不知道在哪里放置它以及确切使用的功能.
labels = c("Citrus", "Crop", "Cypress Swamp", ..........)
(我正在使用Windows 7,Rstudio)