尝试做一个汇总表,它将为我提供最小值,四分位数1,中位数,四分位数3和最大值的箱须图我已经做了。
我创建盒须图的代码可以工作,但无法使汇总表工作。
箱须图代码:
ggplot(mpg, aes(drv,cty)) +
geom_boxplot(colour = "purple") +
labs(x = "Drive Type (drv)", y = "City MPG (cty)", title = "Correlation
between Drive Type and City Miles per Gallon (MPG)") +
theme_light()
当前代码汇总表(不工作)-请注意,我知道这个代码肯定是不正确的。
我知道这是第一行或两行是不正确的。
一次尝试:
df <- ggplot(data = mpg, aes(x=drv, y=cty)) + geom_boxplot()
Summary<-boxplot(df)$stats
colnames(Summary)<-c("4","f","r")
rownames(Summary)<-c("Min","First Quartile","Median","Third Quartile","Max")
Summary
第二次尝试:
Summary<-geom_boxplot(mpg, aes(drv,cty))$stats
colnames(Summary)<-c("4","f","r")
rownames(Summary)<-c("Min","First Quartile","Median","Third Quartile","Max")
Summary
1条答案
按热度按时间zzlelutf1#
使用一个小的自定义函数来计算箱形图统计数据
dplyr::reframe
(需要dplyr >= 1.1.0
)和tidyr::pivot_wider
,您可以执行以下操作: