STHDA forum

Plotting, data visualizations » Adding legend to basic plot? Trying to add legend

Slingshot booster

rank_0.png

Avatar

Signed up since: 31/07/2018

Messages: 1

On 07/31/2018 at 21h07
Howdy,
I'm trying to add a legend to using the basic plot function. I've started with this example:
(http://www.sthda.com/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way)

# Generate some data
x<-1:10; y1=x*x; y2=2*y1
plot(x, y1, type="b", pch=19, col="red", xlab="x", ylab="y")
# Add a line
lines(x, y2, pch=18, col="blue", type="b", lty=2)
# Add a legend
legend(1, 95, legend=c("Line 1", "Line 2"),
col=c("red", "blue"), lty=1:2, cex=0.8)

And modified it to look like this. basic graph is created but not the legend?

plot(C$Ymd,C$ma30,type="l",col="red",ylab="Sunspots",xlab="Year")
lines(C$Ymd,C$ma60,type="l", col="blue")
lines(C$Ymd,C$ma90,type="l", col="green")
legend(10,10,legend=c("30 Days","60 Days","90 Days"),
col=c("red","blue","green"),lty=1:2, cex=0.8)
grid(col="black")

TIA,
DAvid
   
Answer
You aren't allowed to write in this category
1 User online : 0 Administrator, 0 Moderator, 0 Member and 1 Visitor
User online : No member online