Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

How to draw nested categorical boxplots in R using ggplot2? | Salaries | StatswithR | Arnab Hazra

Автор: StatswithR

Загружено: 2020-12-31

Просмотров: 10030

Описание:

Here we explain how to generate a presentation/publication-quality nested categorical boxplots in R/R-studio using ggplot2. The codes for the steps explained in the video are as follows. Copy and paste them into R, run them one-by-one and try to understand what each argument is doing.

#datascience #datavisualization #visualization #ggplot2 #tidyverse #nestedboxplot #categoricalboxplot #boxplot #nested #categorical #Salaries #Salariesdataset #rstudio #rcoding


library(carData)
data("Salaries", package = "carData")

library(writexl)
write_xlsx(Salaries[ , c(1, 2, 6)], path = "Salaries.xlsx")

library(readxl)
data = read_excel("Salaries.xlsx")

head(data)
str(data)

library(ggplot2)

p = ggplot(data = data, aes(x=rank, y=salary / 1e3, fill=discipline)) + geom_boxplot()
ggsave(p, filename = "ggplot_nestbox1.pdf", height = 8, width = 8)

ranks = c("AsstProf", "AssocProf", "Prof")
data$rank = factor(data$rank, levels = ranks)
data$discipline = factor(data$discipline, levels = c("A", "B"))
data$salary = data$salary / 1e3

str(data)

p = ggplot(data = data, aes(x=rank, y=salary, fill=discipline)) + geom_boxplot()
ggsave(p, filename = "ggplot_nestbox2.pdf", height = 8, width = 8)

levels(data$rank) = c("Assistant Prof.", "Associate Prof.", "Full Prof.")
levels(data$discipline) = c("Theoretical", "Applied")

p = ggplot(data = data, aes(x=rank, y=salary, fill=discipline)) + geom_boxplot()
ggsave(p, filename = "ggplot_nestbox3.pdf", height = 8, width = 8)

p = ggplot(data = data, aes(x=rank, y=salary, fill=discipline)) +
stat_boxplot(geom = "errorbar") + geom_boxplot()
ggsave(p, filename = "ggplot_nestbox4.pdf", height = 8, width = 8)

p = ggplot(data = data, aes(x=rank, y=salary, fill=discipline)) +
stat_boxplot(geom = "errorbar") + geom_boxplot() +
ggtitle("Salary comparison") + xlab(NULL) + ylab("Nine-month salary (in thousands USD)")
ggsave(p, filename = "ggplot_nestbox5.pdf", height = 8, width = 8)

p0 = ggplot(data = data, aes(x=rank, y=salary, fill=discipline)) +
stat_boxplot(geom = "errorbar") + geom_boxplot() +
ggtitle("Salary comparison") + xlab(NULL) + ylab("Nine-month salary (in thousands USD)") +
theme(axis.text=element_text(size=18),
axis.title=element_text(size=18),
plot.title = element_text(size=20, hjust = 0.5))
ggsave(p0, filename = "ggplot_nestbox6.pdf", height = 8, width = 8)

p = p0 + theme(legend.text=element_text(size=18),
legend.title = element_text(size=18, hjust = 0.5),
legend.key.height = unit(2,"cm"),
legend.key.width = unit(2,"cm"),
legend.position = c(0.2, 0.8)) +
guides(fill=guide_legend(title="Discipline"))
ggsave(p, filename = "ggplot_nestbox7.pdf", height = 8, width = 8)

cols = rep(c("#E69F00", "#56B4E9"), length(levels(data$rank)))

p = p0 + theme(legend.text=element_text(size=18),
legend.title = element_text(size=18, hjust = 0.5),
legend.key.height = unit(2,"cm"),
legend.key.width = unit(2,"cm"),
legend.position = c(0.2, 0.8)) +
guides(fill=guide_legend(title="Discipline")) +
scale_fill_manual(values=cols)
ggsave(p, filename = "ggplot_nestbox8.pdf", height = 8, width = 8)

How to draw nested categorical boxplots in R using ggplot2? | Salaries | StatswithR | Arnab Hazra

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

How to draw multiple functions together in R using ggplot2? | StatswithR | Arnab Hazra

How to draw multiple functions together in R using ggplot2? | StatswithR | Arnab Hazra

How to draw spatial maps in R using ggmap without Google API key? | IMD | StatswithR | Arnab Hazra

How to draw spatial maps in R using ggmap without Google API key? | IMD | StatswithR | Arnab Hazra

20 R Packages You Should Know

20 R Packages You Should Know

ggplot2 explained 10 nice plots to visualise data  disitribution, histo, denisty, boxplot, raincloud

ggplot2 explained 10 nice plots to visualise data disitribution, histo, denisty, boxplot, raincloud

How to download, process, plot, and animate Covid-19 data in R? | Part 1 | StatswithR | Arnab Hazra

How to download, process, plot, and animate Covid-19 data in R? | Part 1 | StatswithR | Arnab Hazra

Using the the ggplot2 R package to create a boxplot with individual data points overlayed (CC091)

Using the the ggplot2 R package to create a boxplot with individual data points overlayed (CC091)

Основы ПЛК: структурированный текст

Основы ПЛК: структурированный текст

How to draw a function in R using ggplot2? | StatswithR | Arnab Hazra

How to draw a function in R using ggplot2? | StatswithR | Arnab Hazra

How to draw a bivariate continuous function in R using ggplot2? | Heatmap | StatswithR | Arnab Hazra

How to draw a bivariate continuous function in R using ggplot2? | Heatmap | StatswithR | Arnab Hazra

PERFECT PLOTS IN #R ! 💪 {sjPlot} | Easily Visualize Data And Model Results

PERFECT PLOTS IN #R ! 💪 {sjPlot} | Easily Visualize Data And Model Results

boxplot for comparison | before and after| group cross group comparison| ggplot2| R

boxplot for comparison | before and after| group cross group comparison| ggplot2| R

How to get terrain data and draw spatial maps in R using ggplot2? | StatswithR | Arnab Hazra

How to get terrain data and draw spatial maps in R using ggplot2? | StatswithR | Arnab Hazra

Создавайте красивые графики в R: 5 быстрых способов улучшить графики ggplot2

Создавайте красивые графики в R: 5 быстрых способов улучшить графики ggplot2

How to make Boxplots in R More Informative (ggplot2 and Extension Packages)

How to make Boxplots in R More Informative (ggplot2 and Extension Packages)

Bar charts and Histograms using ggplot in R

Bar charts and Histograms using ggplot in R

Очистите свои данные с помощью R. Программирование на R для начинающих.

Очистите свои данные с помощью R. Программирование на R для начинающих.

Using ggplot2's facet_wrap to create three panelled figure in R (CC311)

Using ggplot2's facet_wrap to create three panelled figure in R (CC311)

Столбчатая диаграмма с использованием R с планкой погрешности, визуализация данных, GGplot2, пост...

Столбчатая диаграмма с использованием R с планкой погрешности, визуализация данных, GGplot2, пост...

Change Color of ggplot2 Boxplot in R (3 Examples) | Set col & fill in Plot | Manually Specify Colors

Change Color of ggplot2 Boxplot in R (3 Examples) | Set col & fill in Plot | Manually Specify Colors

Ggplot2 is a lot like Shrek! (grouped boxplot tutorial with pairwise comparisons)

Ggplot2 is a lot like Shrek! (grouped boxplot tutorial with pairwise comparisons)

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com