[R] having more than one plot in one figure

Jannis bt_jannis at yahoo.de
Wed Apr 21 09:36:14 CEST 2010


Where is the problem with your code? You seem to have understood the 
principle correct and all what you want to to is possible with your 
code. You only seem to have made some typos (or is there any other 
reason why you plot num1 twice?), otherwise I do not really understand 
why you can not add num3 and change the plot type to 'b'?

kayj schrieb:
> Hi All,
>
> I have been trying to plot multiple line plots with different colors on one
> figure. in my example below I was able to plot cat vs num1 as a dot plot
> connected with lines but was not able to do that for cat vs num2 and I do
> not know how to add the third plot cat vs num3. below is my code
>
>
> df <- data.frame(cat=1:10, num1=rnorm(10), num2=rnorm(10), num3=rnorm(10))
> plot(df$num1, type="b", col="red", xlab="categories", ylab="random numbers")
> points(df$num1, type="p", pch=21, col="red",bg="red")    #plot "num1" 
> points(df$num2, type="p", pch=21, col="green")   #plot "num2" 
> legend(x="topright", legend=c("num1", "num2"), pch=c(16,16),
> col=c("red","green"))    #add a legend 
>
>
> how to make the second plot of type="b" and how to add a  third plot cat vs
> num3?
>
> I appreciate your help
>
>
>  
>



More information about the R-help mailing list