Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a plot joining points from two measurement times?

First question here! I have two columns of data and each row are a pair of values. I want to plot the first column and the second column vertically and have a line connecting each pair of values, something that looks like this figure in the following link:

http://www.sciencedirect.com/science/article/pii/S0300957297000440#gr1 enter image description here

If you know how to do it, in any tools, such as R, or python, perl, excel, please let me know!

like image 526
olala Avatar asked Nov 28 '22 21:11

olala


2 Answers

And another R approach using matpoints and matlines (and boxplot)

dd <- data.frame(x=rnorm(15), y= rnorm(15))

boxplot(dd, boxwex = 0.3)
# note that you need to transpose `dd`
matpoints(y= t(dd), x= c(1.17,1.83),pch=19, col='black')
matlines(y= t(dd), x= c(1.2,1.8), lty=1, col = 'black')

enter image description here

like image 142
mnel Avatar answered Dec 03 '22 09:12

mnel


Here's an R approach with ggplot2, a bit quick and dirty:

library(ggplot2)

df <- data.frame(baseline=c(1,1,2,2,3,3,4,5,6,7,8,9,10,11),
                 sixmos  =c(5,6,5,7,8,9,10,12,12,2,1,5,2,3))

data <- data.frame(group = factor(1:nrow(df)), 
                   cat=c(rep('baseline',nrow(df)), 
                   rep('sixmos',nrow(df))), 
                   values=c(df$baseline,df$sixmos))

ggplot(data, aes(x=cat, y=values)) + 
  geom_line(aes(group=group)) + 
  geom_point(aes(group=group)) +
  geom_boxplot(data=df, aes(x='baselin', y=baseline)) + 
  geom_boxplot(data=df, aes(x='sixmos2', y=sixmos))

boxplots and slopegraph with ggplot2 in R

Also see this answer: Line charts by group

like image 39
patrickmdnet Avatar answered Dec 03 '22 08:12

patrickmdnet