ggplot和scales软件包未正确计算/打印百分比
我在将条形图转换为百分比(Y轴)时遇到了困难,因此尝试使用秤包。它起作用了,但是图表中代表的百分比不正确。我不知道它用来确定百分比的分母。有人知道如何/在哪里找到它并检查或更改它吗?这是我正在使用的代码:
OSU_Pre_Student_Ex$employ <- factor(OSU_Pre_Student_Ex$employ, levels =
c("Undergraduate student", "Pre-licensure student", "Master's student", "Doctoral student"))
OSU_Pre_Student_Ex$employ<-as.factor(OSU_Pre_Student_Ex$employ)
OSU_Pre_Student_Ex$employ = fct_infreq(OSU_Pre_Student_Ex$employ)
OSU_Pre_Student_Ex %>%
filter(!is.na(employ)) %>%
ggplot(aes(x =employ, fill= employ, drop.na = TRUE)) +
geom_bar(show.legend = FALSE)+
xlab("Student type") +
ylab("Percent") +
coord_cartesian(ylim = c(0, 100))+
scale_y_continuous(labels = scales::percent_format(accuracy=1, scale = 1))+
scale_fill_manual(values = BarGraphPalette5, drop = TRUE) +
theme_minimal(base_family="Calibri")+
theme(panel.grid.major = element_line(size = 0.2), panel.grid.minor = element_line(size= 0.1))+theme(panel.grid.major.x = element_blank(), axis.text.x
=element_text(size=12),axis.text.y = element_text(size = 12))+
scale_x_discrete(limits = levels(OSU_Pre_Student_Ex$employ))
末端的输出(在视觉上看起来不错,但数字却不好): 在此处输入图像描述
I was having trouble converting my bar chart to percentages (y-axis) and so have tried using the scales package. It worked, but the percentages that it is representing in the chart are not correct. I do not know what denominator it is using to determine the percentages. Does anyone know how/where to find this and check it or change it? Here is the code I'm using:
OSU_Pre_Student_Ex$employ <- factor(OSU_Pre_Student_Ex$employ, levels =
c("Undergraduate student", "Pre-licensure student", "Master's student", "Doctoral student"))
OSU_Pre_Student_Ex$employ<-as.factor(OSU_Pre_Student_Ex$employ)
OSU_Pre_Student_Ex$employ = fct_infreq(OSU_Pre_Student_Ex$employ)
OSU_Pre_Student_Ex %>%
filter(!is.na(employ)) %>%
ggplot(aes(x =employ, fill= employ, drop.na = TRUE)) +
geom_bar(show.legend = FALSE)+
xlab("Student type") +
ylab("Percent") +
coord_cartesian(ylim = c(0, 100))+
scale_y_continuous(labels = scales::percent_format(accuracy=1, scale = 1))+
scale_fill_manual(values = BarGraphPalette5, drop = TRUE) +
theme_minimal(base_family="Calibri")+
theme(panel.grid.major = element_line(size = 0.2), panel.grid.minor = element_line(size= 0.1))+theme(panel.grid.major.x = element_blank(), axis.text.x
=element_text(size=12),axis.text.y = element_text(size = 12))+
scale_x_discrete(limits = levels(OSU_Pre_Student_Ex$employ))
The output on my end (which visually looks good but the numbers are not):
enter image description here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论