Multiple mailboxes on the same site with ggplot2

The standard R line creates 30 boxes in one graph when I use this code:

boxplot(Abundance[Quartile==1]~Year[Quartile==1],col="LightBlue",main="Quartile1 (Rare)") 

I would like to create something similar in ggplot2. While I'm using this:

 d1 = data.frame(x=data$Year[Quartile==1],y=data$Abundance[Quartile==1]) a <- ggplot(d1,aes(x,y)) a + geom_boxplot() 

There are 30 years of data. In each year, there are 145 species. In each year, 145 species are divided into quartiles 1-4.

However, I only get one notepad using this. Any idea how to get 30 boxes (one for each year) along the x axis? Any help is greatly appreciated.

There are 30 years of data. In each year, there are 145 species. In each year, 145 species are divided into quartiles 1-4.

+4
source share
1 answer

What does str(d1) say about x ? If a numeric or integer, then this may be your problem. If Year is a factor, then you get a box for each year. As an example:

 library(ggplot2) # Some toy data df <- data.frame(Year = rep(c(1:30), each=20), Value = rnorm(600)) str(df) 

Note that Year is an integer variable

 ggplot(df, aes(Year, Value)) + geom_boxplot() # One boxplot ggplot(df, aes(factor(Year), Value)) + geom_boxplot() # 30 boxplots 
+8
source

Source: https://habr.com/ru/post/1415532/


All Articles