r - ggplot 仅绘制垂直线?
问题描述
输入以下代码时,我得到一个奇怪的 ggplot ,它在其中绘制垂直线。
ggplot(data = otherdata, aes(x = subject, y = pct_.below)) + geom_point(aes(colour = subgroup))
当做geom_point
而不是geom_line
,我得到另一个图。我不知道为什么会这样。点数多于子组数,但这不是问题的解决方案。我该怎么做才能修复这个ggplot?
# dummy data
set.seed(45)
df <- data.frame(x=rep(1:5, 9), val=sample(1:100, 45),
variable=rep(paste0("category", 1:9), each=5))
# plot
ggplot(data = df, aes(x=x, y=val)) + geom_line(aes(colour=variable))
我刚刚发布的代码有效,但我不知道这两个代码之间有什么区别。
前 20 行数据:
structure(list(subject = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Algebra II",
"Biology I", "Chemistry", "English I", "English II", "English III",
"Geometry", "Int Math I", "Int Math II", "Int Math III", "US History"
), class = "factor"), pct_.below = c(0, 12.5, 12.4, 12.5, 0,
0, 12.5, 8.4, 11.1, 12.8, 11.9, 0, 11.5, 9, 100, 66.7, 100, 100,
100, 50), subgroup = structure(c(2L, 3L, 4L, 5L, 7L, 10L, 11L,
12L, 13L, 15L, 16L, 17L, 18L, 19L, 3L, 4L, 5L, 8L, 10L, 11L), .Label = c("All Students",
"Asian", "Black or African Amer", "Black/Hispanic/Native Amer",
"ED", "English Learner T 1-2", "English Learner T 1-4", "English Learners",
"English Learners with T 1-2", "English Learners with T 1-4",
"Hispanic", "Non-Black/Hispanic/Native Amer", "Non-ED", "Non-English Learners/T 1-2",
"Non-English Learners/T 1-4", "Non-Students with Disabilities",
"Students with Disabilities", "Super Subgroup", "White"), class = "factor")), row.names = c(2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 32L,
33L, 34L, 35L, 36L, 37L), class = "data.frame")
解决方案
推荐阅读
- flutter - 如何在 Flutter 中进行“收据验证”?
- javascript - Angular 的 nativeElement 的 offsetWidth 为 0
- python - Gensim 导入错误“ImportError:DLL 加载失败:%1 不是有效的 Win32 应用程序。”
- objective-c - ios 13 - 带有 UISearchBar _searchField 的自定义 SearchBar 不起作用
- java - System.arraycopy 性能
- c# - 实体之间通过服务层进行通信
- python - 如何添加带有回调功能的 WeakValueDictionary?
- android - 启用/禁用夜间模式时如何从另一个活动重新创建活动?
- python - 如何通过“ResourceNotFound:请求的资源不存在”错误
- reactjs - 我在哪里可以找到我的 projet 在反应中的文件夹,我在我的桌面上看不到它