I would like to plot a graph with different lines for each row, and that the column names are assigned to the X axis. For finishing, I would also like to make every line different from the other with a legend for the reader.
Thank you in advance.
My data:
Average 2003-2005 Average 2006-2008 Average 2009-2010 Average 2011-2013 Average 2014-2016
31.48489 32.53664 30.41938 30.53870 31.15550
18.78799 17.78141 17.58791 17.03071 17.25654
107.46615 107.71512 109.55090 110.31438 109.66492
> str(Table_1_2003_2018_All)
'data.frame': 3 obs. of 6 variables:
$ Average 2003-2005: num 31.5 18.8 107.5
$ Average 2006-2008: num 32.5 17.8 107.7
$ Average 2009-2010: num 30.4 17.6 109.6
$ Average 2011-2013: num 30.5 17 110.3
$ Average 2014-2016: num 31.2 17.3 109.7
$ Average 2017-2018: num 31.8 16.8 109.8
Code:
# Plot 1
colnames(Table_1_2003_2018_All) <- c("2003-2005","2006-2008","2009-2010","2011-2013","2014-2016","2017-2018")
plot(seq_along(Table_1_2003_2018_All),
Table_1_2003_2018_All[1,], type="l", xaxt = 'n',xlab = 'Time Periods', ylab = 'Average',
main = "MARKET WORK", ylim = c(30,35)
)
axis(1, at = 1:6, colnames(Table_1_2003_2018_All))
Thanks in advance.
We can specify the 'x' as numeric
ie sequence of columns and then change the x labels with axis
plot(seq_along(Table_1_2003_2018_All),
Table_1_2003_2018_All[1,], type="l", xaxt = 'n',
xlab = 'colnames', ylab = 'first row')
axis(1, at = 1:5, colnames(Table_1_2003_2018_All))
If we need to plot lines for each row, use matplot
matplot(t(Table_1_2003_2018_All), type = 'l', xaxt = 'n')
legend("top", legend = seq_len(nrow(Table_1_2003_2018_All)),
col= seq_len(nrow(Table_1_2003_2018_All)),cex=0.8,
fill=seq_len(nrow(Table_1_2003_2018_All)))
axis(1, at = 1:5, colnames(Table_1_2003_2018_All))
Table_1_2003_2018_All <- structure(list(Average2003.2005 = c(31.48489, 18.78799, 107.46615
), Average2006.2008 = c(32.53664, 17.78141, 107.71512), Average2009.2010 = c(30.41938,
17.58791, 109.5509), Average2011.2013 = c(30.5387, 17.03071,
110.31438), Average2014.2016 = c(31.1555, 17.25654, 109.66492
)), class = "data.frame", row.names = c(NA, -3L))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.