您好,我想用R脚本创建与下图类似的图表:
图片来源:https://community.tableau.com/thread/194440
这是我的R代码:
library(ggplot2)
ifile <- read.table("C:/ifiles/test.txt", skip = 2, header = TRUE, sep="\t")
ifileVI <- data.frame(ifile["VI"], ifile["Site"])
x<-quantile(ifileVI$VI,c(0.01,0.99))
data_clean <- ifileVI[bfileVI$VI >=x[1] & ifileVI$VI <=x[2],]
p <- ggplot(data_clean, aes(x = Site, y = VI, group=Site)) + geom_boxplot() + geom_histogram(binwidth = 0.05)
p
然而,我遇到了以下错误:
Error: stat_bin() must not be used with a y aesthetic.
bfileVI:
Id VI Site
WFR1 2.91 1
WFR1 2.89 2
WFR1 2.86 3
WFR1 2.91 4
WFR1 2.87 1
WFR1 2.67 2
WFR1 2.76 3
WFR1 2.74 4
WFR1 2.98 4
WFR1 2.89 3
WFR1 2.55 4
WFR1 2.96 3
WFR1 2.71 1
WFR1 2.98 2
WFR1 2.89 3
WFR2 2.55 2
WFR2 2.86 4
WFR2 2.91 3
WFR2 287 1
WFR2 2.74 2
WFR2 2.98 1
WFR2 2.89 2
WFR2 2.55 3
WFR2 2.96 4
WFR2 2.71 1
WFR2 2.86 2
WFR2 2.91 3
WFR2 287 4
WFR2 2.67 1
WFR2 2.76 2
WFR2 2.74 3
WFR2 2.98 4
WFR2 2.89 1
WFR2 2.55 2
WFR2 2.96 3
WFR2 2.71 4
WFR2 2.98 1
WFR2 2.89 2
WFR2 2.55 3
WFR2 2.86 4
dput()
函数分享您的数据。 - Tung