1
 Name     A         D
 ChN     24.22      21.66
 YuE     17.26      21.26
 MiE     14.90      12.25
 ChS     13.45      20.68
 ZhW     12.51      23.02
 HeW     10.47      12.50
 HeE     12.87      22.39
 LeW     15.01      22.43
 ChW     12.05      12.83
 LeE     15.26      12.94
 Shg     12.96      12.18
 YiW     13.36      12.74
 Qig     10.47      12.98
 GuN     12.66      12.80

I have the above data frame, and I want to plot both columns A and D with respect to column name in R using the following lines, however in the R, X axis becomes numbers and Y axis shows two different labels. Can you please help me to know where the problem is and what is the correct method to do it?

plot(df$D, xlab=NULL,ylab=NULL, type="b",las=2,pch = 1,add=TRUE)
par(new=TRUE)
plot(df$A,xaxt = "n", xlab="", type="b",las=2,pch = 1,add=TRUE)

Thanks! Leo!

13554N
  • 37
  • 9
  • It seems like it would make more sense as a bars than lines, but with ggplot2, `library(tidyverse); df %>% mutate(Name = factor(Name, levels = Name)) %>% gather(var, val, -Name) %>% ggplot(aes(Name, val, color = var, group = var)) + geom_point() + geom_line()` – alistaire Jan 12 '17 at 22:03
  • Thanks. But, actually what I need is a line chart to show the trends wrp. to column name. to show how each column changes. Sine the name column shows the spatial positions. I couldn't get why my question is duplicate, could you please give me the link for? – 13554N Jan 12 '17 at 23:03

0 Answers0