0

I am not sure where I am going wrong.
I have encountered several errors and am attempting to troubleshoot but I'm not understanding the issue. I would appreciate it if you could help me out. My goal is to have a boxplot that has girth on y axis, ForestDiv on x axis, and the ForestDiv needs to be converted to a factor (I think I did this already, but may have screwed it up), and then ForestDiv needs to be reordered by the mean of LatDec.
RStudioScreenshot RstudioScreenshot.
I have already constructed a boxplot previously, and the only updates needed are what I stated above.

Error in f(): ! Aesthetics must be valid data columns. Problematic aesthetic(s): y = FactorForestDiv ~ .... Did you mistype the name of a data column or forget to add after_stat()? Backtrace:

  1. base (local) <fn>(x)
  2. ggplot2:::print.ggplot(x)
  3. ggplot2:::ggplot_build.ggplot(x)
  4. ggplot2 (local) by_layer(function(l, d) l$compute_aesthetics(d, plot))
  5. ggplot2 (local) f(l = layers[[i]], d = data[[i]])
  6. l$compute_aesthetics(d, plot)
  7. ggplot2 (local) f(..., self = self)
Join_Macro_Site %>%
 ggplot(mapping = aes(FactorForestDiv ~ fct_reorder(girth, data = FactorForestDiv, ylim(0,200), .fun = mean(LatDec)))) + 
 geom_boxplot() +
 ylim(0,200)

Error in `f()`:
! Aesthetics must be valid data columns. Problematic aesthetic(s): x = FactorForestDiv ~ .... 
Did you mistype the name of a data column or forget to add after_stat()?
Backtrace:
 1. base (local) `<fn>`(x)
 2. ggplot2:::print.ggplot(x)
 4. ggplot2:::ggplot_build.ggplot(x)
 5. ggplot2 (local) by_layer(function(l, d) l$compute_aesthetics(d, plot))
 6. ggplot2 (local) f(l = layers[[i]], d = data[[i]])
 7. l$compute_aesthetics(d, plot)
 8. ggplot2 (local) f(..., self = self)

Join_Macro_Site %>%
 ggplot(mapping = aes() + 
 geom_boxplot() +
 FactorForDiv <- factor(FactorForDiv, levels = data(order(mean(LatDec)), "ForestDiv", levels(ForestDiv)
 ylim(0,200)

Error: unexpected symbol in:
"FactorForDiv <- factor(FactorForDiv, levels = data(order(mean(LatDec)), "ForestDiv", levels(ForestDiv)
ylim"

Join_Macro_Site %>%
 ggplot(mapping = aes() + 
 geom_boxplot() +
 Join_Macro_Site$ForestDiv <- factor(Join_Macro_Site$ForestDiv, levels = Join_Macro_Site[order(Join_Macro_Site$LatDec), "ForestDiv"])
 levels(Join_Macro_Site$ForestDiv)

Error: unexpected symbol in:
"Join_Macro_Site$ForestDiv <- factor(Join_Macro_Site$ForestDiv, levels = Join_Macro_Site[order(Join_Macro_Site$LatDec), "ForestDiv"])
levels"

Join_Macro_Site %>%
 ggplot(mapping = aes() + 
 geom_boxplot() +
 Join_Macro_Site$ForestDiv <- factor(Join_Macro_Site$ForestDiv, levels = Join_Macro_Site[order(Join_Macro_Site$LatDec), "ForestDiv"])
 levels(Join_Macro_Site$ForestDiv) %>%

Error: unexpected symbol in:
"Join_Macro_Site$ForestDiv <- factor(Join_Macro_Site$ForestDiv, levels = Join_Macro_Site[order(Join_Macro_Site$LatDec), "ForestDiv"])
levels"

Join_Macro_Site %>%
 ggplot(mapping = aes() + 
 geom_boxplot() +
 Join_Macro_Site$ForestDiv <- factor(Join_Macro_Site$ForestDiv, levels = Join_Macro_Site[order(Join_Macro_Site$LatDec), "ForestDiv"]), levels(Join_Macro_Site$ForestDiv) %>%
 ylim(0,200)

Error: Incomplete expression: Join_Macro_Site %>%
ggplot(mapping = aes() + 
geom_boxplot() +
Join_Macro_Site$ForestDiv <- factor(Join_Macro_Site$ForestDiv, levels = Join_Macro_Site[order(Join_Macro_Site$LatDec), "ForestDiv"]), levels(Join_Macro_Site$ForestDiv) %>%
ylim(0,200)
Dave2e
  • 22,192
  • 18
  • 42
  • 50
six
  • 1
  • First start with: `Join_Macro_Site %>% ggplot(mapping = aes(y= girth, x=ForestDiv)) + geom_boxplot()`, and see if that gets something to work with. Also post your data using the output of the `dput()` function, the screen shot of the data is almost useless. – Dave2e Sep 22 '22 at 00:21
  • I already had what you typed input for the previous question, and that is as far as I got before I had a bunch of errors. I am not familiar with the dput() option but I will try to use it. I'm mostly unsure how to go from ```Join_Macro_Site %>% ggplot(mapping = aes(y= girth, x=ForestDiv)) + geom_boxplot()``` and then convert ForestDiv to a factor, and then reorder by the mean of LatDec. I believe I may have messed up when converting ForestDiv to a factor. – six Sep 22 '22 at 01:35
  • https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Dave2e Sep 22 '22 at 01:52

0 Answers0