Change Axis Labels of Boxplot in R (Example) | Base R, ggplot2 & reshape2 Packages | Relevel Factors

preview_player
Показать описание
R code of this video:

x2 = rnorm(100, 2),
x3 = rnorm(100, 3, 3))
head(data) # Head of example data

boxplot(data) # Boxplot in Base R

boxplot(data, # Change labels of boxplot
names = c("Name_A",
"Name_B",
"Name_C"))

library("reshape2") # Load reshape2 package

data_long <- melt(data) # Reshape data
head(data_long) # Head of reshaped data

library("ggplot2") # Load ggplot2

ggplot(data_long, aes(variable, value)) + # Boxplot in ggplot2
geom_boxplot()

data_long_labels <- data_long # Duplicate data
levels(data_long_labels$variable) <- c("Name_A", # Relevel factor labels
"Name_B",
"Name_C")

ggplot(data_long_labels, aes(variable, value)) + # Boxplot with updated labels
geom_boxplot()

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

Joachim,

Perhaps you could go over the use of some of the more cryptic functions like "pull()" and "autoplot()"

haraldurkarlsson
Автор

Hi! Why I can't knit at last? It could run before knit, but it went wrong as "Error in `attr(groups, "names") <- names`:" when I try to knit.

TsingEvelyn
Автор

how do i make a boxplot with my dependent variable being a dummy and my independent variable being a quantitative variable. thank you

SylvesterAdetor-zxqv
Автор

Excellent video! Thanks for share with us!

keityfarfan
Автор

Thanks a lot 🙏,
I Hope you talk about (seet.seed) function in detail

abbasdwain
Автор

Is there a way to change the size of the names on the x axis?

klumpchen
Автор

Hi, you look a willing person, can you help me with a problem?
i have a df with some columns, but a want to change the values of a column
accordingly with the values of another column, exemple:
...column 4... column 9
... "X" ... "Y"
... "Z" ... "Y"
... "Z" ... "XX"

So if the column 4 is "Z" i want the column 9 change the value of the rows for "XXX" so it will be:
...column 4... column 9
... "X" ... "Y"
... "Z" ... "XXX"
... "Z" ... "XXX"
Ty a lot..

isaacfritsch
Автор

I cannot read your code, even with a 27 inch screen

alexandermarsden