简体   繁体   English

如何使用ggplot在代表数据帧两列的两点之间绘制多条线

[英]how to plot multiple lines between two points representing in two columns of a data frame using ggplot

hello everyone I have the following data frame: 大家好,我有以下数据框:

Here is my df: 这是我的df:

C1 <- c(-1.363953,4.265514,5.609484,7.524796,2.562210,7.214769, 4.667354,4.950837,4.134733,7.540626)
C2 <- c(-1.541836,4.248582,5.557042,7.475255,2.424585,7.125046,4.524404  4.890195,3.945435,7.488123)

Name <- paste(letters[1:10])
df <- data.frame(Name = paste(letters[1:10]), C1, C2)


Name        C1        C2.     
 a      -1.363953   -1.541836  
 b       4.265514    4.248582  
 c       5.609484    5.557042  
 d       7.524796    7.475255  
 e       2.562210    2.424585  
 f       7.214769    7.125046  
 g       4.667354    4.524404  
 h       4.950837    4.890195  
 i       4.134733    3.945435  
 j       7.540626    7.488123 

How can I draw a line between two values of column c1 and c2 at each row. 如何在每一行的列c1和c2的两个值之间绘制一条线。 I would like to have 10 lines which connect C1 entry at each row to C2 entry. 我想用10条线将每行的C1条目连接到C2条目。

For example I want to have line between -1.363953 and -1.541836? 例如,我想在-1.363953和-1.541836之间设置线?

Do you have any idea how can I do this using ggplots in r? 您是否知道如何在r中使用ggplots做到这一点? Thanks 谢谢

library(ggplot2)
library(reshape2)

df = melt(df)

ggplot(df,aes(x=variable,y=value,group=Name,colour=Name)) + 
  geom_line()

Produces this: 产生这个:

在此处输入图片说明

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

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