【发布时间】:2019-09-07 02:30:54
【问题描述】:
我正在尝试使用 ggplot 创建四个百分比系列的线图。下面包含的示例数据...输出应将“周”作为 x 轴,并将每个系列的数字百分比作为单独的 y 轴线图。
我已尝试按照Plot multiple columns on the same graph in R 的说明进行操作。数据框融化得很好,但绘图失败。
此测试的数据:将以下内容另存为“pct.txt”并根据提供的代码使用 dget。
结构(列表(NoRep = c(“2.2%”,“10.7%”,“7.9%”,“100%”,“100%”, “5.6%”、“2.9%”、“3%”、“3.9%”、“4.7%”、“3.9%”、“3.1%”、“2%”、“2.4%”、 “2.4%”、“17.7%”、“2.1%”、“7.4%”、“1.9%”、“8%”),报告 = c(“46.5%”, “33.4%”、“36.4%”、“0%”、“0%”、“42.2%”、“43.8%”、“39.2%”、“36.8%”、 “36.1%”、“36.1%”、“35.8%”、“37.7%”、“26.6%”、“26.9%”、“53.4%”、 "39.9%", "32.9%", "40.9%", "41.9%"), Mobile_Internet = c("14.4%", “13.6%”、“1.2%”、“0%”、“0%”、“2.4%”、“11.7%”、“11%”、“10.2%”、 “10.1%”、“9.1%”、“39.8%”、“39%”、“39.2%”、“38.8%”、“16.8%”、“31.1%”、 "29.2%", "28.8%", "27.4%"), Mobile_SMS = c("36.9%", "42.3%", "54.5%", “0%”、“0%”、“49.9%”、“41.6%”、“46.8%”、“49.1%”、“49%”、“50.9%”、 “21.3%”、“21.2%”、“31.9%”、“31.9%”、“12%”、“26.9%”、“30.5%”、“28.3%”、 "22.7%"), 周 = c("2018_W48", "2018_W49", "2018_W50", "2018_W51", “2018_W52”、“2019_W01”、“2019_W02”、“2019_W03”、“2019_W04”、 “2019_W05”、“2019_W06”、“2019_W07”、“2019_W08”、“2019_W09”、 “2019_W10”、“2019_W11”、“2019_W12”、“2019_W13”、“2019_W14”、“2019_W15” )), .Names = c("NoRep", "Report", "Mobile_Internet", "Mobile_SMS", "周"), row.names = c("2018_W48", "2018_W49", "2018_W50", "2018_W51", “2018_W52”、“2019_W01”、“2019_W02”、“2019_W03”、“2019_W04”、 “2019_W05”、“2019_W06”、“2019_W07”、“2019_W08”、“2019_W09”、 “2019_W10”、“2019_W11”、“2019_W12”、“2019_W13”、“2019_W14”、 "2019_W15"), class= "data.frame")
test <- dget(file="pct.txt")
tmp <- melt(test, id.vars = "Week")
ggplot(tmp, aes(Week, value, col=variable))+
geom_line()
我收到错误“geom_path:每个组仅包含一个观察值。您需要 调整群体审美?”
【问题讨论】:
标签: r