chris8813
chris8813

Reputation: 1

r program two scatter plots Line of best fit

I have columns with log_100m, log_1500m and indicator for female. I have created scatter plot for female and male in different color and I made legend for male and female. I have to make best fit for both male and female. However, I dont really get how to make two different best fit. Moreover, is there anyway to put legend outside of graph? Thankz

plot(tnffinal$log_100m,tnffinal$log_1500m, col=ifelse(tnffinal$Female==1,"red", "blue"))

legend("right", pch=c(1,1), col=c("red", "blue"), c("Female", "Male"), bty="o", cex=.8, box.col="darkgreen")

Upvotes: 0

Views: 266

Answers (1)

Hammad Sheikh
Hammad Sheikh

Reputation: 21

You could use the ggplot2 package. It makes creating a publication ready plot really easy. You can create your graph and move things around layer by layer. The code for plotting your graph would be:

# set up the plot
myplot <- qplot(data=tnffinal, log_100m, log_1500m, color=Female)
# add Least Squares fit lines (you can chose other methose like Loess)
myplot_fit <- myplot+geom_smoot(method=lm)
# output graph
myplot_fit

Upvotes: 0

Related Questions