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
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()