r - 在 ggplot2 中,如何使绘制的数据透明?
问题描述
我试图让左图像右图一样。蓝线是由“stat_smoot 函数”创建的线性回归。我试图找到这样做的函数,但它没有用。
此外,以下是我编写的代码数据。[代码]
fbdata <- read.csv("congress-data.csv", stringsAsFactors = FALSE)
new_df <-fbdata %>%
group_by(screen_name)%>%
mutate(average_likes = mean(likes_count), average_haha = mean(haha_count))
new_df <- new_df[, -c(2, 3, 4, 5, 6)]
new_df
p_one <- ggplot(new_df, aes(x=average_likes, y=average_haha)) + stat_smooth(method = "lm", se = T, na.rm = T) +
xlab("Average number of likes per post") + ylab("Average number of HAHA reactions") +
ggtitle("Senator Tommey, Congressman Duncan, and Congresswoman Waters are the funniest legislators on
Facebook") +
scale_x_log10(breaks =c(100, 10000)) + scale_y_log10(breaks = c(1,100)) +
theme_minimal()
p_one
p_one <- p_one + geom_text(aes(label=screen_name, alpha = average_haha), fontface ="bold") +
theme(legend.position = "none")
p_one
[数据样本]
name average_likes average_haha
<dbl> <dbl>
1 RepEspaillat 10.4 0.0652
2 CongressmanCulberson 10.3 0.0833
3 RepAndyBiggs 74.1 2.59
4 derek.kilmer 171. 0.978
5 CongressmanNadler 64.8 0.283
6 repsaludcarbajal 247. 0.727
7 RepBobbyScott 70.7 0.455
8 SenatorTomCotton 652. 4.26
9 RepMarkDeSaulnier 106. 1.18
10 RepDavidEPrice 232. 0.5
我怎样才能做到这一点?你能推荐一些功能或建议吗?
解决方案
推荐阅读
- javascript - 从父组件调用时,angular 2 变量在子组件方法中返回 null
- fullcalendar - 如何使用 fullCalendar 的 validRange 功能?
- snowflake-cloud-data-platform - 雪花查询性能调优
- python - Python (Selenium) - 使用 Xpath 时选择器无效
- mysql - 如果存在匹配,则查询以获取具有所需数据的行,否则为NULL,多个表?
- macos - VLC在mac上编译找不到MacOSX.sdk
- windows - wglMakeCurrent 的正确用法?
- python-3.x - 如何插入一个 numpy 数组以使其达到一定长度?
- python - 如何将按列和按行的 DataFrame 合并到一维数组中?
- ubuntu - Ansible 命令不是从 rubdeck GUI 运行的