首页 > 解决方案 > 在 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 

我怎样才能做到这一点?你能推荐一些功能或建议吗?

标签: rggplot2

解决方案


推荐阅读