我在科学杂志上发表一篇论文,附有一些箱形图,我有两个数字,并且它们上面有不同数量的箱形图。我希望绘图条的宽度相同。我不想控制整个情节的宽度,而是控制条纹。
这就是我所拥有的:
Clades<-c("C-A","C-A","C-A","C-A","C-A","C-A","C-A","C-A","C-A","C-B","C-B","C-B","C-B","C-B","C-B","C-B","C-B","C-C","C-C","C-C","C-C","C-C","C-C","C-C","C-C","C-D","C-D","C-D","C-D","C-D","C-D","C-D","C-D","G-A","G-A","G-A","G-A","G-A","G-A","G-A","G-A","G-A","G-A","G-A","G-B","G-B","G-B","G-B","G-B","G-B","G-B","G-B","G-B","G-B","G-C","G-C","G-C","G-C","G-C","G-C","G-C","G-D","G-D","G-D","G-D","G-D","G-D","G-D","G-D","G-D","G-D","G-D","G-E","G-E","G-E","G-E","G-E","G-E","G-E","G-E","G-E","G-E")
NoGClades<-c("C-A","C-A","C-A","C-A","C-A","C-A","C-A","C-A","C-A","C-B","C-B","C-B","C-B","C-B","C-B","C-B","C-B","C-C","C-C","C-C","C-C","C-C","C-C","C-C","C-C","C-D","C-D","C-D","C-D","C-D","C-D","C-D","C-D","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G","G")
HapDiv<-c(12,23,12,34,12,34,12,34,12,115,123,12,34,45,123,3,23,13,156,14,5,14,14,11,12,12,34,12,34,12,115,123,12,34,45,123,3,23,12,23,12,12,23,12,123,12,34,45,12,34,12,12,34,12,13,156,14,5,12,34,45,115,123,12,14,14,11,34,12,34,12,34,123,3,23,12,23,12,12,13,156,14)
Haplotypes<-data.frame(Clades,NoGClades,HapDiv) # create data frame
plot(Haplotypes$Clades, Haplotypes$HapDiv,
xlab="Clade", ylab="Haplotype Diversity",
main="Haplotype Diversity with Clades in G")
plot(Haplotypes$NoGClades, Haplotypes$HapDiv,
xlab="Clade", ylab="Haplotype Diversity",
main="Haplotype Diversity with no Clades in G")
因为有不同数量的条形图 - 两个图形中各个条形图的宽度不同。如何控制它们的宽度以使它完全相等?
总的来说,我也希望能够直接控制箱形图的外观。
答案 0 :(得分:2)
您可以使用ggplot2
创建情节。
使用tidyr
:
library(tidyr)
dat <- gather(Haplotypes, variable, value, -HapDiv)
重命名因子级别:
levels(dat$variable) <- c("Haplotype Diversity with Clades in G",
"Haplotype Diversity with no Clades in G")
简介:
library(ggplot2)
ggplot(dat, aes(x = value, y = HapDiv)) +
geom_boxplot() +
facet_grid(. ~ variable, scales = "free_x", space = "free_x") +
xlab("Clade") +
theme_bw()