在R中,使用Tidyverse并导出一个Ggplot2图,应该如何构建数据库来实现这样的图
?这就像是在数着日子,直到达到一个目标。是否需要进行时间格式化?我的思路应该是怎样的?谢谢你
bq3bfh9z1#
下面是一个可能的例子:
library(dplyr) library(ggplot2) df <- structure(list(Months = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), Software = c(rep("Twitter", 10), rep("Facebook", 10), rep("Chat GPT", 10)), Users = c(50, 10, 200, 400, 800, 160, 3200, 6400, 1280, 2000, 4000, 800, 1600, 3200, 6400, 128000, 2560, 5120, 102400, 150, 6000, 1200, 2400, 400, 960, 19200, 3800, 7680, 1000, 20)), class = "data.frame", row.names = c(NA, -30L), .Names = c("Months", "Software", "Users")) df %>% mutate(Cumulative_Users = cumsum(Users)) %>% group_by(Software) %>% filter(Cumulative_Users >= 10000) %>% summarise(Months_to_10000= min(Months)) %>% ggplot(aes(x = Months_to_10000, y = reorder(Software, Months_to_10000))) + geom_col() + labs(x = "Months to reach 10000 users", y = "Software") + geom_text(aes(label = paste(round(Months_to_10000, 1), "months")), hjust = -0.1)+ theme_minimal()
字符串
的数据
1条答案
按热度按时间bq3bfh9z1#
下面是一个可能的例子:
字符串
的数据