[R] create line chart from data.frame

Jim Lemon jim at bitwrit.com.au
Wed May 21 10:37:46 CEST 2014


On Wed, 21 May 2014 01:20:52 AM Mat wrote:
> Hello together,
> 
> i want to create a line graph, from a data.frame like this one:
>           Categorie      Y10_11   Y11_12    Y12_13      Y13_14
> A        Service              1           2           3               4
> B        Support             2           5            5               0
> C        Telephone         1            3           1               10
> D        Online              10           12         6                8
> E        Offline               8            7          0                2
> F        Hotline              15          18         7                3
> 
> Is there any way, to create a line chart, with the years (Y10_11, etc.) in
> the X-axis and the Categorie in the Y-axis. The lines should be created 
with
> the numbers for each categorie. So in each plot there should be 6 
lines in
> dependence of the value for each year.

Hi Mat,
Try this:

mwdf<-read.table(text=
"Categorie Y10_11 Y11_12 Y12_13 Y13_14
 Service              1      2     3       4
 Support             2      5     5       0
 Telephone         1      3     1      10 
 Online              10   12      6       8
 Offline               8      7      0       2
 Hotline              15  18      7      3",
 header=TRUE)
matplot(t(mwdf[,2:5]),type="b",xaxt="n")
axis(1,at=1:4,labels=names(mwdf)[2:5])
legend(3,17,mwdf[,1],pch=as.character(1:6),col=1:6)

Jim



More information about the R-help mailing list