Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selecting a range of values in a specific column for R ggplot

I am trying to select a range of values (i.e. the first 4 values) in a specific column from a table. The column is called "RL45". I tried the following code to create a plot in ggplot:

newplot <- ggplot(data = GEV, aes(x = RL45[1:4])) + geom_density(color = 
"midnightblue") + xlab("Location (mm/day") + ggtitle("Global Location under RCP4.5") + 
xlim(300, 350)

This results in this strange error:

Error: Aesthetics must be either length 1 or the same as the data (34): x

This is odd, as I selected the first 4 values in that "RL45" column.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any thoughts would be greatly appreciated!

Thank you,

>Solution :

It looks like you just need to change where you subset.

newplot <- ggplot(data = GEV[1:4], aes(x = RL45)) + geom_density(color = 
    "midnightblue") + xlab("Location (mm/day") + ggtitle("Global Location under RCP4.5") + 
    xlim(300, 350)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading