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:
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()
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
Splitting Dataframes in R Based on Empty Rows
Error with H2O in R - Can't Connect to Local Host
Get Value of Last Non-Na Row Per Column in Data.Table
R Error: Cannot Coerce Type 'Closure' to Vector of Type 'Double'
How to Read Column Names 'As Is' from CSV File
How to Use User Input to Obtain a Data.Frame from My Environment in Shiny
Split Multiple Comma-Separated Column into Separate Rows
Change Value to Percentage of Row in R
How to Place an Identical Smooth on Each Facet of a Ggplot2 Object
R: Holt-Winters with Daily Data (Forecast Package)
How to Edit Column Names in Datatable Function When Running R Shiny App
Conditionally Remove Leading or Trailing '.' Character in R
Click on Cross Domain Iframe Element Using Rselenium
Plot a Function with Several Arguments in R
Calculating the Distance Between Points in Different Data Frames
R: Using "Microbenchmark" and Ggplot2 to Plot Runtimes
Combining Rows Based on a Column
Download .Rdata and .CSV Files from Ftp Using Rcurl (Or Any Other Method)