Home > OS >  Error in `check_required_aesthetics()`: ! geom_dotplot requires the following missing aesthetics: y
Error in `check_required_aesthetics()`: ! geom_dotplot requires the following missing aesthetics: y

Time:06-24

The problem is that whilst I try to plot using geom_dotplot, I receive the error:

 Error in `check_required_aesthetics()`:
! geom_dotplot requires the following missing aesthetics: y

The data for this problem is:

sum.qmerge<-structure(list(absdif = c(0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.01, 
0, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0, 0.01, 0.01, 0.01, 0.01, 
0.02, 0.02, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.01, 0.01, 
0.01, 0.01, 0.01, 0, 0, 0.01, 0.01, 0.01, 0.01, 0, 0, 0, 0.01, 
0.01, 0.01, 0.01, 0.01, 0.01, 0, 0.01, 0.02, 0.02, 0.02, 0.01, 
0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.01, 0.02, 0.02, 
0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.03, 0.03, 0.03, 0.02, 0.02, 
0.02, 0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0, 0, 0.01, 0, 0, 
0, 0, 0, 0.01, 0.01, 0.01, 0, 0, 0, 0, 0.01, 0.01, 0.01, 0.01, 
0.01, 0, 0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0, 0.01, 0.01, 
0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.01, 0.01
), landscape = c("cluster", "cluster", "cluster", "cluster", 
"cluster", "cluster", "cluster", "cluster", "cluster", "cluster", 
"cluster", "cluster", "cluster", "cluster", "cluster", "cluster", 
"cluster", "cluster", "cluster", "cluster", "cluster", "cluster", 
"cluster", "cluster", "cluster", "cluster", "cluster", "cluster", 
"cluster", "cluster", "cluster", "cluster", "cluster", "cluster", 
"cluster", "cluster", "cluster", "cluster", "cluster", "cluster", 
"cluster", "cluster", "cluster", "cluster", "cluster", "cluster", 
"cluster", "cluster", "cluster", "regular", "regular", "regular", 
"regular", "regular", "regular", "regular", "regular", "regular", 
"regular", "regular", "regular", "regular", "regular", "regular", 
"regular", "regular", "regular", "regular", "regular", "regular", 
"regular", "regular", "regular", "regular", "regular", "regular", 
"regular", "regular", "regular", "regular", "regular", "regular", 
"regular", "regular", "regular", "regular", "regular", "regular", 
"regular", "regular", "regular", "regular", "regular", "regular", 
"regular", "regular", "regular", "regular", "random", "random", 
"random", "random", "random", "random", "random", "random", "random", 
"random", "random", "random", "random", "random", "random", "random", 
"random", "random", "random", "random", "random", "random", "random", 
"random", "random", "random", "random", "random", "random", "random", 
"random", "random", "random", "random", "random", "random", "random", 
"random", "random", "random", "random", "random", "random", "random", 
"random", "random", "random", "random", "random")), row.names = c(NA, 
-147L), class = c("tbl_df", "tbl", "data.frame"))

The code I am using to plot this data is:

ggplot(sum.qmerge) geom_dotplot(aes(x = landscape, y = absdif),dotsize=0.5,binwidth = 0.2) 
  theme(aspect.ratio = 1) 
  xlab("Landscape Type") 
  ylab("Absolute Difference")

I have tried adding the aesthetic function to both ggplot() and geom_dotplot() but I keep receiving the error. What is the solution? Many thanks.

CodePudding user response:

The plot will run if you remove y = absdif from your code. However, you may not find the resulting plot particularly exciting! Are you sure a dotplot is what you want? It's hard to know what you wanted to show without knowing more, but perhaps a bar chart would be more appropriate?

ggplot(sum.qmerge)   geom_bar(aes(x = landscape, fill = as.factor(absdif)))

CodePudding user response:

You can get the dotplot by adjusting the binaxis and stackdir options:

library(tidyverse)

sum.qmerge <- structure(list(absdif = c(
  0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
  0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01,
  0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.01,
  0, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0, 0.01, 0.01, 0.01, 0.01,
  0.02, 0.02, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.01, 0.01,
  0.01, 0.01, 0.01, 0, 0, 0.01, 0.01, 0.01, 0.01, 0, 0, 0, 0.01,
  0.01, 0.01, 0.01, 0.01, 0.01, 0, 0.01, 0.02, 0.02, 0.02, 0.01,
  0.01, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.01, 0.02, 0.02,
  0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.03, 0.03, 0.03, 0.02, 0.02,
  0.02, 0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0, 0, 0.01, 0, 0,
  0, 0, 0, 0.01, 0.01, 0.01, 0, 0, 0, 0, 0.01, 0.01, 0.01, 0.01,
  0.01, 0, 0, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0, 0.01, 0.01,
  0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.01, 0.01
), landscape = c(
  "cluster", "cluster", "cluster", "cluster",
  "cluster", "cluster", "cluster", "cluster", "cluster", "cluster",
  "cluster", "cluster", "cluster", "cluster", "cluster", "cluster",
  "cluster", "cluster", "cluster", "cluster", "cluster", "cluster",
  "cluster", "cluster", "cluster", "cluster", "cluster", "cluster",
  "cluster", "cluster", "cluster", "cluster", "cluster", "cluster",
  "cluster", "cluster", "cluster", "cluster", "cluster", "cluster",
  "cluster", "cluster", "cluster", "cluster", "cluster", "cluster",
  "cluster", "cluster", "cluster", "regular", "regular", "regular",
  "regular", "regular", "regular", "regular", "regular", "regular",
  "regular", "regular", "regular", "regular", "regular", "regular",
  "regular", "regular", "regular", "regular", "regular", "regular",
  "regular", "regular", "regular", "regular", "regular", "regular",
  "regular", "regular", "regular", "regular", "regular", "regular",
  "regular", "regular", "regular", "regular", "regular", "regular",
  "regular", "regular", "regular", "regular", "regular", "regular",
  "regular", "regular", "regular", "regular", "random", "random",
  "random", "random", "random", "random", "random", "random", "random",
  "random", "random", "random", "random", "random", "random", "random",
  "random", "random", "random", "random", "random", "random", "random",
  "random", "random", "random", "random", "random", "random", "random",
  "random", "random", "random", "random", "random", "random", "random",
  "random", "random", "random", "random", "random", "random", "random",
  "random", "random", "random", "random", "random"
)), row.names = c(
  NA,
  -147L
), class = c("tbl_df", "tbl", "data.frame"))

ggplot(sum.qmerge, aes(landscape, absdif))  
  geom_dotplot(binaxis = "y", stackdir = "center", dotsize = 0.2)  
  theme(aspect.ratio = 1)  
  xlab("Landscape Type")  
  ylab("Absolute Difference")
#> Bin width defaults to 1/30 of the range of the data. Pick better value with `binwidth`.

Created on 2022-06-23 by the reprex package (v2.0.1)

  • Related