Two data sets on R line graph, but using same X and Y axis?

后端 未结 1 1537
死守一世寂寞
死守一世寂寞 2021-01-28 00:46

I\'m trying to plot two lines on a graph in R. The data is related to death row, with the CSV having three columns: first column is the year, second is death row population and

相关标签:
1条回答
  • 2021-01-28 01:11

    Here is how I would do it:

    deathrow <- read.csv("death_row_by_year.csv", sep=",", header=T)
    plot(range(deathrow$Year, na.rm=T), range(c(deathrow$Population, deathrow$Executions)), na.rm=T), type='n')
    lines(deathrow$Year, deathrow$Population, col="red")
    lines(deathrow$Year, deathrow$Executions, col="green")
    

    The most important piece here is the call to plot with type='n', so there is no point plotted but the axis are set up to the right limits. Arguably, you may also specify these limits with xlim=range(...) and ylim=range(...) in the calls to lines.

    0 讨论(0)
提交回复
热议问题