英文:
R plot date data multiple geom_line
问题
绘制以下数据。 尝试在图中包括每种技术的线条,不使用facetwrap。绘制技术和文件数量 -
日期 | emmm | 任务 | coll_task | 技术 | 文件数 |
---|---|---|---|---|---|
2023-06-01 | vnmenm1 | tr | e3g_tr_vnmenm1 | 3g | 1136 |
2023-06-01 | vnmenm1 | tr | e4g_tr_vnmenm1 | 4g | 3475 |
2023-06-01 | vnmsgsn1 | tr | e4g_tr_vnmsgsn1 | 4g | 317 |
2023-06-03 | vnmenm1 | tr | e3g_tr_vnmenm1 | 3g | 1136 |
2023-06-03 | vnmenm1 | tr | e4g_tr_vnmenm1 | 4g | 8899 |
2023-06-03 | vnmsgsn1 | tr | e4g_tr_vnmsgsn1 | 4g | 296 |
2023-06-04 | vnmenm1 | tr | e3g_tr_vnmenm1 | 3g | 1136 |
2023-06-04 | vnmenm1 | tr | e4g_tr_vnmenm1 | 4g | 9034 |
2023-06-04 | vnmsgsn1 | tr | e4g_tr_vnmsgsn1 | 4g | 292 |
使用以下代码 -
data %>% group_by(Date, emmm, tech, filescount) %>% summarize(filescount = sum(filescount)) %>% ggplot(aes(Date, emmm, tech, color = filescount)) + geom_point(size = 2.4, alpha = 0.5) + geom_line(aes(x = Date, y = emmm), size = 1, alpha = 0.4, stat = "identity", na.rm = TRUE)
有没有办法同时显示技术和文件数量,即 - 按技术和文件数量绘制geom_line!
英文:
Plotting the below data. trying to include the lines per tech, Without using the facetwrap.
Plot both tech and files per enm --
Date | emmm | task | coll_task | tech | filescount |
---|---|---|---|---|---|
2023-06-01 | vnmenm1 | tr | e3g_tr_vnmenm1 | 3g | 1136 |
2023-06-01 | vnmenm1 | tr | e4g_tr_vnmenm1 | 4g | 3475 |
2023-06-01 | vnmsgsn1 | tr | e4g_tr_vnmsgsn1 | 4g | 317 |
2023-06-03 | vnmenm1 | tr | e3g_tr_vnmenm1 | 3g | 1136 |
2023-06-03 | vnmenm1 | tr | e4g_tr_vnmenm1 | 4g | 8899 |
2023-06-03 | vnmsgsn1 | tr | e4g_tr_vnmsgsn1 | 4g | 296 |
2023-06-04 | vnmenm1 | tr | e3g_tr_vnmenm1 | 3g | 1136 |
2023-06-04 | vnmenm1 | tr | e4g_tr_vnmenm1 | 4g | 9034 |
2023-06-04 | vnmsgsn1 | tr | e4g_tr_vnmsgsn1 | 4g | 292 |
Using below code -
data %>% group_by(Date, emmm, tech, filescount) %>% summarize(filescount = sum(filescount)) %>% ggplot(aes(Date, emmm, tech, color = filescount)) + geom_point(size = 2.4, alpha = 0.5) + geom_line(aes(x = Date, y = emmm), size = 1, alpha = 0.4, stat = "identity", na.rm = TRUE)
Any way to present with both tech and showing the filescount, i.e - geom_line per tech and filescount !
答案1
得分: 1
library(ggplot2)
library(dplyr)
# 作为数据框的给定测试数据
df <- data.frame(
Date = as.Date(c("2023-06-01", "2023-06-01", "2023-06-01", "2023-06-03", "2023-06-03", "2023-06-03", "2023-06-04", "2023-06-04", "2023-06-04")),
emmm = c("vnmenm1", "vnmenm1", "vnmsgsn1", "vnmenm1", "vnmenm1", "vnmsgsn1", "vnmenm1", "vnmenm1", "vnmsgsn1"),
task = rep("tr", 9),
coll_task = c("e3g_tr_vnmenm1", "e4g_tr_vnmenm1", "e4g_tr_vnmsgsn1", "e3g_tr_vnmenm1", "e4g_tr_vnmenm1", "e4g_tr_vnmsgsn1", "e3g_tr_vnmenm1", "e4g_tr_vnmenm1", "e4g_tr_vnmsgsn1"),
tech = c("3g", "4g", "4g", "3g", "4g", "4g", "3g", "4g", "4g"),
filescount = c(1136, 3475, 317, 1136, 8899, 296, 1136, 9034, 292)
)
# 创建一个用于绘图的数据框
df_sum <- df %>%
group_by(emmm, tech, Date) %>%
summarize(total_files = sum(filescount), .groups = 'drop')
# 绘制数据
ggplot(df_sum, aes(x = Date, y = total_files, group = interaction(emmm, tech), color = interaction(emmm, tech), linetype = interaction(emmm, tech))) +
geom_line() +
geom_point() +
labs(x = "Date", y = "Files per Tech", color = "Tech", linetype = "Tech") +
scale_color_discrete(name = "Emmm - Tech", labels = c("vnmenm1 - 3g", "vnmenm1 - 4g", "vnmsgsn1 - 4g")) +
scale_linetype_discrete(name = "Emmm - Tech", labels = c("vnmenm1 - 3g", "vnmenm1 - 4g", "vnmsgsn1 - 4g")) +
theme_minimal()
输出:
英文:
library(ggplot2)
library(dplyr)
# Your given test data as a dataframe
df <- data.frame(
Date = as.Date(c("2023-06-01", "2023-06-01", "2023-06-01", "2023-06-03", "2023-06-03", "2023-06-03", "2023-06-04", "2023-06-04", "2023-06-04")),
emmm = c("vnmenm1", "vnmenm1", "vnmsgsn1", "vnmenm1", "vnmenm1", "vnmsgsn1", "vnmenm1", "vnmenm1", "vnmsgsn1"),
task = rep("tr", 9),
coll_task = c("e3g_tr_vnmenm1", "e4g_tr_vnmenm1", "e4g_tr_vnmsgsn1", "e3g_tr_vnmenm1", "e4g_tr_vnmenm1", "e4g_tr_vnmsgsn1", "e3g_tr_vnmenm1", "e4g_tr_vnmenm1", "e4g_tr_vnmsgsn1"),
tech = c("3g", "4g", "4g", "3g", "4g", "4g", "3g", "4g", "4g"),
filescount = c(1136, 3475, 317, 1136, 8899, 296, 1136, 9034, 292)
)
# Create a dataframe to plot
df_sum <- df %>%
group_by(emmm, tech, Date) %>%
summarize(total_files = sum(filescount), .groups = 'drop')
# Plot the data
ggplot(df_sum, aes(x = Date, y = total_files, group = interaction(emmm, tech), color = interaction(emmm, tech), linetype = interaction(emmm, tech))) +
geom_line() +
geom_point() +
labs(x = "Date", y = "Files per Tech", color = "Tech", linetype = "Tech") +
scale_color_discrete(name = "Emmm - Tech", labels = c("vnmenm1 - 3g", "vnmenm1 - 4g", "vnmsgsn1 - 4g")) +
scale_linetype_discrete(name = "Emmm - Tech", labels = c("vnmenm1 - 3g", "vnmenm1 - 4g", "vnmsgsn1 - 4g")) +
theme_minimal()
Output:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论