Ggplot2_Error: Geom_Point Requires the Following Missing Aesthetics: Y

Plotting DataFrame in R ggplot shows an error for aesthetics

In ggplot for aesthetics, you should not index your dataframe, it gets all the variables by itself.

I don't know your dataframe structure exactly because of bad format of your question, but may be it is what you want:

library(ggplot2)
library(tidyverse)

# creating a dataframe similar to yours
habSolyc05g052129.2 <- data.frame(
Shab_ovul1 = 0,
Shab_poll1 = 0.6145496,
Shab_poll2 = 0.368,
Shab_styl1 = 0.043,
Shab_styl2 = 0.0026,
Shab_styl3 = 0.0405
)

# reshaping daraframe to ling format
habSolyc05g052129.2 <- habSolyc05g052129.2 %>%
pivot_longer(cols = 1:6, names_to = "Variables", values_to = "Values")

# main plot
ggplot(habSolyc05g052129.2, aes(x = Variables, y = Values)) +
geom_point()

The output:
Sample Image

How to solve: geom_linerange requires the following missing aesthetics: x, ymin, ymax

The geom_linerange only allows a range for y as indicated by the error. So Just flip your x and y values, and then use coord_flip to swap the x and y axes when plotting.

ggplot(dt3) + 
geom_point(aes(y=mean_salary, x=employee_name, colour=category_boss),
position = position_dodge(-.5)) +
geom_linerange(aes(ymin=min_salary, ymax=max_salary, x=employee_name, colour=category_boss),
position = position_dodge(-.5)) +
coord_flip()

Sample Image

Error in `check_required_aesthetics()`: ! geom_linerange requires the following missing aesthetics: x, ymin and ymax or y, xmin and xmax

This error appears to be caused by a clash with other libraries. I do not know which library. To solve the error I unloaded all libraries, restarted R, and loaded only ggplot2.
On running the code I pointed to in the comment above, it now produced the same result as the OP of that question.
I tried rerunning the code I have above, and I now get (awful!) plots and no error.



Related Topics



Leave a reply



Submit