stanley cho
stanley cho

Reputation: 153

Is there a way to combine 2 boxplots into 1?

The code I have so far gives me 2 boxplots, but I was just wondering if

there is a way to combine these 2 boxplots into one (By combining "Type_1"and "Type_2).

poke = read.csv("pokemon_2018.csv",TRUE,",")
par(mfrow = c(1,2))

boxplot(poke[,"Attack"]~ poke[,"Type_1"],main="Pokemon Attacks by 
Type_1",las=2)

boxplot(poke[,"Attack"]~ poke[,"Type_2"],main="Pokemon Attacks by 
Type_2",las=2)

Upvotes: 1

Views: 908

Answers (1)

Cactus
Cactus

Reputation: 924

I would strongly recommend using ggplot2. Boxplots are easy to create. Example, using the iris dataset (since you did not provide your data):

library(ggplot2)
plot1 <- ggplot(data = iris, aes(x=Species, y=Sepal.Width)) +
geom_boxplot()

Will give you three boxplots, based on Species type:

enter image description here

More information can be found here: http://t-redactyl.io/blog/2016/04/creating-plots-in-r-using-ggplot2-part-10-boxplots.html

Upvotes: 1

Related Questions