r - 如何在ggplot2中将颜色添加到构面网格
问题描述
我在 ggplot 中做了一个 facet_grid,如下所示:
ggplot(DATASET, aes((jitter(WordCount)),Retweet, group=1))+
geom_point(aes(alpha=1/150))+
facet_grid(Dictionary ~ ., margins = TRUE, scales = "free")+
labs(x = "Word Count", y = "Retweet Count", title = "A")+
theme_bw()+
theme(legend.position = "none")
如何使每个图形使用不同颜色的点?
作为参考,这是我的数据框的结构:
data.frame': 939006 obs. of 4 variables:
$ Retweet : num 1388 762 748 436 342 ...
$ id : int 1 2 3 4 5 6 7 8 9 10 ...
$ Dictionary: Factor w/ 3 levels "Emotional","Moral",..: 1 1 1 1 1 1 1 1 1 1 ...
$ WordCount : num 1 1 2 2 1 1 3 1 2 1 ...
解决方案
正如评论中回答的那样,为颜色美学分配一个变量。
ggplot(DATASET, aes(WordCount), etweet, group = 1, color = Dictonary)) +
geom_jitter(aes(alpha = 1/150)) +
facet_grid(Dictionary ~ ., margins = TRUE, scales = "free") +
labs(x = "Word Count", y = "Retweet Count", title = "A") +
theme_bw() +
theme(legend.position = "none")
推荐阅读
- python - 通过线性插值组合两个不同的时间戳数据帧
- f# - 如何根据 Power Query 中的 Power BI 参数中的逗号分隔值列表删除行?
- r - 如何为 R 包开发解决“在调用‘list’时不允许缺少参数”?
- wpf - SignalR WPF 服务器 - 如何触发播放器?
- c# - 在 for-each 签名中使用方法调用与将方法分配给变量并将变量用作循环的对象
- javascript - 无法读取 null 的属性“getElementById”
- php - 为类使用命名空间
- macos - MacOS 终端中的实际颜色与其在首选项中的值不匹配
- firebase - 找不到 com.google.firebase:firebase-crashlytics-gradle:17.0.0-beta01
- android - 在 OpeGL ES Android 中更改背景颜色会更改纹理颜色