Популярное

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

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

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

Топ запросов

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

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

Автор: StatswithR

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

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

Описание:

Here we explain how to generate a presentation/publication-quality plot in R/R-studio using ggplot2 where we want to draw multiple functions together. 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 #multiple #function #rstudio #rcoding #timeseries #continuous #discrete #discontinuous #normal #exponential

rm(list = ls())

library(ggplot2)

xx = seq(-5, 5, length.out = 1e4)

d1 = dnorm(xx, mean = 0, sd = 1)
d2 = dnorm(xx, mean = 0, sd = 1.5)
d3 = dnorm(xx, mean = 0, sd = 2)

#-------------

p = ggplot() + geom_line(aes(x = xx, y = d1, color = "black")) +
geom_line(aes(x = xx, y = d2, color = "red")) +
geom_line(aes(x = xx, y = d3, color = "blue"))

ggsave(p, filename = "multiple_lines_1.pdf", height = 6, width = 6)

#-------------

p0 = ggplot() + geom_line(aes(x = xx, y = d1, color = "black"), size = 1.5) +
geom_line(aes(x = xx, y = d2, color = "red"), size = 1.5) +
geom_line(aes(x = xx, y = d3, color = "blue"), size = 1.5)

ggsave(p0, filename = "multiple_lines_2.pdf", height = 6, width = 6)

#-------------

p = p0 + xlab("Value") + ylab("Density")

ggsave(p, filename = "multiple_lines_3.pdf", height = 6, width = 6)

#-------------

p = p0 + xlab("Value") + ylab("Density") +
ggtitle("Density comparison") +
theme(plot.title = element_text(hjust = 0.5))

ggsave(p, filename = "multiple_lines_4.pdf", height = 6, width = 6)

#-------------

p1 = p0 + xlab("Value") + ylab("Density") +
ggtitle("Density comparison") +
theme(plot.title = element_text(hjust = 0.5)) +
theme(axis.text=element_text(size=20),
axis.title=element_text(size=20),
plot.title = element_text(size=20))

ggsave(p1, filename = "multiple_lines_5.pdf", height = 6, width = 6)

#-------------

p = p1 + scale_color_identity(breaks = c("black", "red", "blue"))

ggsave(p, filename = "multiple_lines_6.pdf", height = 6, width = 6)

#-------------

p = p1 + scale_color_identity(breaks = c("black", "red", "blue"),
guide = "legend")

ggsave(p, filename = "multiple_lines_7.pdf", height = 6, width = 6)

#-------------

p = p1 + scale_color_identity(breaks = c("black", "red", "blue"),
guide = "legend",
name = "SD variation",
labels = c("SD = 1", "SD = 1.5", "SD = 2"))

ggsave(p, filename = "multiple_lines_8.pdf", height = 6, width = 6)

#-------------

p2 = p1 + scale_color_identity(breaks = c("black", "red", "blue"),
guide = "legend",
name = "SD variation",
labels = c(expression(paste(sigma, " = 1", sep = "")),
expression(paste(sigma, " = 1.5", sep = "")),
expression(paste(sigma, " = 2", sep = ""))))

ggsave(p2, filename = "multiple_lines_9.pdf", height = 6, width = 6)

#-------------

p = p2 + theme(legend.text.align = 0)

ggsave(p, filename = "multiple_lines_10.pdf", height = 6, width = 6)

#-------------

p = p2 + theme(legend.text.align = 0,
legend.position = c(0.8, 0.8))

ggsave(p, filename = "multiple_lines_11.pdf", height = 6, width = 6)

#-------------

p = p2 + theme(legend.text.align = 0,
legend.position = c(0.8, 0.8),
legend.key = element_rect(fill = "transparent"))

ggsave(p, filename = "multiple_lines_12.pdf", height = 6, width = 6)

#-------------

p = p2 + theme(legend.text.align = 0,
legend.position = c(0.8, 0.8),
legend.key = element_rect(fill = "transparent"),
legend.text=element_text(size=20),
legend.title = element_text(size=20))

ggsave(p, filename = "multiple_lines_13.pdf", height = 6, width = 6)

#-------------

p = p2 + theme(legend.text.align = 0,
legend.position = c(0.8, 0.8),
legend.key = element_rect(fill = "transparent"),
legend.text=element_text(size=20),
legend.title = element_text(size=20),
legend.key.width = unit(1,"cm"))

ggsave(p, filename = "multiple_lines_14.pdf", height = 6, width = 6)

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

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

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

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

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

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

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

How to draw a time series in R using ggplot2? | Single, Multiple | StatswithR | Arnab Hazra

How to draw a time series in R using ggplot2? | Single, Multiple | StatswithR | Arnab Hazra

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

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

R Functions Explained

R Functions Explained

How to create a nice bar chart in R using ggplot2? | Top 10 economies | StatswithR | Arnab Hazra

How to create a nice bar chart in R using ggplot2? | Top 10 economies | StatswithR | Arnab Hazra

Rstudio Tutorial

Rstudio Tutorial

Visually enhanced overlapping histogram and density plot in R

Visually enhanced overlapping histogram and density plot in R

Научитесь строить графики данных с помощью R и GGplot2: импортируйте, изменяйте, стройте графики ...

Научитесь строить графики данных с помощью R и GGplot2: импортируйте, изменяйте, стройте графики ...

How to combine multiple plots in R with cowplot and ggplot2 (CC098)

How to combine multiple plots in R with cowplot and ggplot2 (CC098)

Долбануть по Ирану, отжать Гренландию | Обычный вторник Трампа? (English subtitles)

Долбануть по Ирану, отжать Гренландию | Обычный вторник Трампа? (English subtitles)

ПОЛНЫЙ ПРОВАЛ «ОРЕШНИКА». Путин выставил себя на посмешище

ПОЛНЫЙ ПРОВАЛ «ОРЕШНИКА». Путин выставил себя на посмешище

Гистограммы в R с ggplot и geom_histogram() [Учебное пособие по галерее R-Graph]

Гистограммы в R с ggplot и geom_histogram() [Учебное пособие по галерее R-Graph]

Only 1% Solve This! Germany Math Olympiad Problem

Only 1% Solve This! Germany Math Olympiad Problem

How to Plot a 3D graph | Plotly Tutorial in Rstudio

How to Plot a 3D graph | Plotly Tutorial in Rstudio

Код работает в 100 раз медленнее из-за ложного разделения ресурсов.

Код работает в 100 раз медленнее из-за ложного разделения ресурсов.

How to make 3D spinning scatter plots in R with RGL

How to make 3D spinning scatter plots in R with RGL

Битва за 1-е место! Арджун Эригайси - Жавохир Синдаров. Титульный вторник 2026. Шахматы

Битва за 1-е место! Арджун Эригайси - Жавохир Синдаров. Титульный вторник 2026. Шахматы

Моделирование Монте-Карло

Моделирование Монте-Карло

Draw Multiple Function Curves to Same Plot | Base R & ggplot2 Package | Using curve() & geom_line()

Draw Multiple Function Curves to Same Plot | Base R & ggplot2 Package | Using curve() & geom_line()

How to use the 4 different norm() functions in R

How to use the 4 different norm() functions in R

Понимание Z-преобразования

Понимание Z-преобразования

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



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



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