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
If you know how to do it, in any tools, such as R, or python, perl, excel, please let me know!
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')
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))
Also see this answer: Line charts by group
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With