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

geom_boxplot, it won't let me plot my values, says they are not numeric

I am learning r, and I am practicing with the rivers built in dataset.

I want to make a boxplot of the river length x, but it is not working.

ex of data, full length is 141

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

x
735
320
325
392
524
450

my code

library(tidyverse)

rivers %>% ggplot(mapping = aes(y=x)) +
  geom_boxplot()

I get this error

Error: `data` must be a data frame, or other object coercible by `fortify()`, not a numeric vector.
Run `rlang::last_error()` to see where the error occurred.

It says it is not a numeric vector so I tried using as.numeric(x) but that did not work. It says numeric under "x" when I view it.

>Solution :

The "x" in this data for river length is a numeric vector. You should turn it into a data frame first with data.frame() Also you can change the column name from "x" to avoid any issues with the ggplot mapping.

library(tidyverse)
river <- data.frame(rivers)
river %>% ggplot(mapping = aes(y = rivers)) +
  geom_boxplot()
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