首页 > 解决方案 > ggplot 在 scale_x_discrete 中的中断问题

问题描述

我对 R 很陌生,我在使用 ggplot2 时遇到了问题。

当我第一次尝试在我的数据集中绘制一些点时,我得到了一个带有太多标签的 x 和 y 轴,如下所示:

标签太多

但是当我尝试使用 scale_x_discrete 时,它​​不会显示我指定的所有标签。

这是我使用的代码:

ggplot(schooldata, aes(Economic.Need.Index, Average.Math.Proficiency)) 
+ geom_point() 
+ scale_x_discrete(name = "Economic Need Index", breaks = c("0", "0.2", "0.4", "0.6", "0.8", "1"), labels = c("0", "0.2", "0.4", "0.6", "0.8", "1")) 
+ scale_y_discrete(name = "Average Math Proficiency", breaks = c("1", "2", "3", "4"), labels = c("1", "2", "3", "4"))

这是我的情节:

它只绘制了几个中断/标签

我知道这可能有一个非常简单的解决方法,我只是非常缺乏经验,我不知道还有什么可以尝试的。任何帮助将不胜感激,谢谢!

标签: rggplot2

解决方案


推荐阅读