ggplot2 箱线图中的平均符号
ggplot2 mean symbol in boxplots
我有以下数据:
GENDER Addressee_gender_and_age likelihood
Female F20 4
Female F20 5
Male F20 3
Female F20 3
Female F20 4
Male F20 1
我有兴趣获取箱线图
p = ggplot(data = melteddata, aes(x=Addressee_gender_and_age, y=likelihood)) +
ggtitle("Distribution of the likelihood of complaining by gender") +
theme(plot.title = element_text(hjust = 0.5)) +
geom_boxplot(aes(fill=GENDER))
p + facet_wrap( ~ Addressee_gender_and_age, scales="free") +
stat_summary(fun=mean, colour="darkred", geom="point",
shape=18, size=3,show_guide = FALSE)
问题是整个包装的平均符号如下:
问题是您将错误的值设置为 x 轴。我首先创建一个可重现的示例 (https://whosebug.com/help/minimal-reproducible-example),然后将 aes(x=age, y=x)
更改为 aes(x=gender, y=x)
在您的示例中它将是 GENDER
而不是 Addressee_gender_and_age
Test<-data.frame(x=rnorm(40),age=rep(c(10,20,30,40,50),8),
gender=rep(c("Male","Female"),20))
library(ggplot2)
ggplot(data = Test, aes(x=age, y=x)) +
geom_boxplot(aes(fill=gender))+
facet_wrap( ~ age, scales="free") +
stat_summary(fun=mean, colour="darkred", geom="point",
shape=18, size=3,show_guide = FALSE)
ggplot(data = Test, aes(x=gender, y=x)) +
geom_boxplot(aes(fill=gender))+
facet_wrap( ~ age, scales="free") +
stat_summary(fun=mean, colour="darkred", geom="point",
shape=18, size=3,show_guide = FALSE)
我有以下数据:
GENDER Addressee_gender_and_age likelihood
Female F20 4
Female F20 5
Male F20 3
Female F20 3
Female F20 4
Male F20 1
我有兴趣获取箱线图
p = ggplot(data = melteddata, aes(x=Addressee_gender_and_age, y=likelihood)) +
ggtitle("Distribution of the likelihood of complaining by gender") +
theme(plot.title = element_text(hjust = 0.5)) +
geom_boxplot(aes(fill=GENDER))
p + facet_wrap( ~ Addressee_gender_and_age, scales="free") +
stat_summary(fun=mean, colour="darkred", geom="point",
shape=18, size=3,show_guide = FALSE)
问题是整个包装的平均符号如下:
问题是您将错误的值设置为 x 轴。我首先创建一个可重现的示例 (https://whosebug.com/help/minimal-reproducible-example),然后将 aes(x=age, y=x)
更改为 aes(x=gender, y=x)
在您的示例中它将是 GENDER
而不是 Addressee_gender_and_age
Test<-data.frame(x=rnorm(40),age=rep(c(10,20,30,40,50),8),
gender=rep(c("Male","Female"),20))
library(ggplot2)
ggplot(data = Test, aes(x=age, y=x)) +
geom_boxplot(aes(fill=gender))+
facet_wrap( ~ age, scales="free") +
stat_summary(fun=mean, colour="darkred", geom="point",
shape=18, size=3,show_guide = FALSE)
ggplot(data = Test, aes(x=gender, y=x)) +
geom_boxplot(aes(fill=gender))+
facet_wrap( ~ age, scales="free") +
stat_summary(fun=mean, colour="darkred", geom="point",
shape=18, size=3,show_guide = FALSE)