简体   繁体   English

我想使用 ggplot2 在单个图中执行多行

[英]I want to do the multiple lines in the single plot using the ggplot2

I am working on a large data set with many rows and columns.我正在处理包含许多行和列的大型数据集。 The data here is showing is portion of it.这里显示的数据是其中的一部分。 I want to put all the values of column b to e against the variable a我想将 b 列的所有值都放到 e 对变量 a

I tried the melt function and looks like it doesn't work.我尝试了融化功能,看起来它不起作用。 Please help me to solve this one by using ggplot2 and if necessary for loop or appy function请帮助我通过使用 ggplot2 来解决这个问题,如有必要,请使用循环或 appy 函数

enter image description here在此处输入图片说明

You can use the function gather() (library tidyr ), that will regroup the column b to e together.您可以使用函数gather() (库tidyr ),它将列b重新组合到e Then, you can plot with ggplot() and split your graph with the function facet_grid() .然后,您可以使用ggplot()绘图并使用函数facet_grid()拆分图形。

df %>% 
gather(2:5, key = myColumns, value = myValues) %>% 
ggplot(aes(x = a, y = myValues, color = myColumns)) + 
geom_line() + 
facet_grid(myColumns ~ .)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM