Популярное

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

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

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

Топ запросов

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

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

Автор: StatswithR

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

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

Описание:

Here we explain how to generate a presentation/publication-quality plot of a bivariate continuous function, or a heatmap, 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 #function #rstudio #rcoding #timeseries #continuous #bivariate #normal #heatmap

mu = c(1, 2)
sigma = c(1, 1.25)
rho = 0.5

covmat = diag(sigma^2)
covmat[1, 2] = covmat[2, 1] = rho * prod(sigma)

mu
covmat

x = seq(from = mu[1] - 3 * sigma[1], to = mu[1] + 3 * sigma[1], by = 0.05)
y = seq(from = mu[2] - 3 * sigma[2], to = mu[2] + 3 * sigma[2], by = 0.05)

loc = expand.grid(x=x, y=y)

#install.packages("emdbook")
library(emdbook)

norm2dens = apply(loc, 1, dmvnorm, mu = mu, Sigma = covmat)

library(ggplot2)

p = ggplot() + geom_tile(aes(x = loc[ , 1], y = loc[ , 2], fill = norm2dens))
ggsave(p, filename = "bivardens_ggplot1.pdf", height = 8, width = 8)

p = ggplot() + geom_tile(aes(x = loc[ , 1], y = loc[ , 2], fill = norm2dens)) +
coord_fixed(ratio = 1)
ggsave(p, filename = "bivardens_ggplot2.pdf", height = 8, width = 8)

p = ggplot() + geom_tile(aes(x = loc[ , 1], y = loc[ , 2], fill = norm2dens),
width = 0.06, height = 0.06) +
coord_fixed(ratio = 1)
ggsave(p, filename = "bivardens_ggplot3.pdf", height = 8, width = 8)

p = ggplot() + geom_tile(aes(x = loc[ , 1], y = loc[ , 2], fill = norm2dens),
width = 0.06, height = 0.06) +
coord_fixed(ratio = 1) +
xlab(expression(X[1])) + ylab(expression(X[2]))
ggsave(p, filename = "bivardens_ggplot4.pdf", height = 8, width = 8)

p0 = ggplot() + geom_tile(aes(x = loc[ , 1], y = loc[ , 2], fill = norm2dens),
width = 0.06, height = 0.06) +
coord_fixed(ratio = 1) +
xlab(expression(X[1])) + ylab(expression(X[2])) +
ggtitle(expression(paste("Density of BVN(", mu[1], "=1, ", mu[2], "=2, ",
sigma[1], "=1, ", sigma[2], "=1.25, ", rho, "=0.5)", sep = ""))) +
theme(plot.title = element_text(hjust = 0.5))
ggsave(p0, filename = "bivardens_ggplot5.pdf", height = 8, width = 8)

p = p0 + theme(axis.text=element_text(size=15),
axis.title=element_text(size=15),
plot.title = element_text(size=18))
ggsave(p, filename = "bivardens_ggplot6.pdf", height = 8, width = 8)

library(viridis)

p = p0 + theme(axis.text=element_text(size=15),
axis.title=element_text(size=15),
plot.title = element_text(size=18)) +
scale_fill_viridis()
ggsave(p, filename = "bivardens_ggplot7.pdf", height = 8, width = 8)

p = p0 + theme(axis.text=element_text(size=15),
axis.title=element_text(size=15),
plot.title = element_text(size=18)) +
scale_fill_viridis(name = "Density") +
theme(legend.title = element_text(size=18, hjust = 0.5),
legend.text=element_text(size=15))
ggsave(p, filename = "bivardens_ggplot8.pdf", height = 8, width = 8)

p = p0 + theme(axis.text=element_text(size=15),
axis.title=element_text(size=15),
plot.title = element_text(size=18)) +
scale_fill_viridis(name = "Density") +
theme(legend.title = element_text(size=18, hjust = 0.5),
legend.text=element_text(size=15),
legend.key.height = unit(1.5,"cm"),
legend.key.width = unit(1.5,"cm"))
ggsave(p, filename = "bivardens_ggplot9.pdf", height = 8, width = 8)

p = p0 + theme(axis.text=element_text(size=15),
axis.title=element_text(size=15),
plot.title = element_text(size=18)) +
scale_fill_viridis(name = "Density") +
theme(legend.title = element_text(size=18, hjust = 0.5),
legend.text=element_text(size=15),
legend.key.height = unit(1.5,"cm"),
legend.key.width = unit(1.5,"cm")) +
scale_x_continuous(expand = expansion(mult = c(0, 0))) +
scale_y_continuous(expand = expansion(mult = c(0, 0)))
ggsave(p, filename = "bivardens_ggplot10.pdf", height = 8, width = 8)

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

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

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

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

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

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

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

array(10) { [0]=> object(stdClass)#5128 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "9wLMjOP9oNs" ["related_video_title"]=> string(98) "How to draw spatial maps in R using ggmap without Google API key? | IMD | StatswithR | Arnab Hazra" ["posted_time"]=> string(21) "4 года назад" ["channelName"]=> string(10) "StatswithR" } [1]=> object(stdClass)#5101 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "oFUbYMFqSP8" ["related_video_title"]=> string(86) "How to draw multiple functions together in R using ggplot2? | StatswithR | Arnab Hazra" ["posted_time"]=> string(21) "4 года назад" ["channelName"]=> string(10) "StatswithR" } [2]=> object(stdClass)#5126 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "tX8RaTp7jL8" ["related_video_title"]=> string(92) "How to get terrain data and draw spatial maps in R using ggplot2? | StatswithR | Arnab Hazra" ["posted_time"]=> string(21) "4 года назад" ["channelName"]=> string(10) "StatswithR" } [3]=> object(stdClass)#5133 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "wjZofJX0v4M" ["related_video_title"]=> string(148) "LLM и GPT - как работают большие языковые модели? Визуальное введение в трансформеры" ["posted_time"]=> string(19) "1 год назад" ["channelName"]=> string(11) "3Blue1Brown" } [4]=> object(stdClass)#5112 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "aircAruvnKk" ["related_video_title"]=> string(101) "Но что такое нейронная сеть? | Глава 1. Глубокое обучение" ["posted_time"]=> string(19) "7 лет назад" ["channelName"]=> string(11) "3Blue1Brown" } [5]=> object(stdClass)#5130 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "OIZAbldPBcI" ["related_video_title"]=> string(42) "Долгожданный МИР. Или..." ["posted_time"]=> string(24) "11 часов назад" ["channelName"]=> string(27) "Анатолий Шарий" } [6]=> object(stdClass)#5125 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "6H9KpfO8zCg" ["related_video_title"]=> string(99) "How to draw a multiple bar chart in R using ggplot2? | Contingency table | StatswithR | Arnab Hazra" ["posted_time"]=> string(21) "4 года назад" ["channelName"]=> string(10) "StatswithR" } [7]=> object(stdClass)#5135 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "B1ULvYY-0Uo" ["related_video_title"]=> string(124) "Закон сохранения энергии — величайшее заблуждение физики [Veritasium]" ["posted_time"]=> string(21) "5 дней назад" ["channelName"]=> string(10) "Vert Dider" } [8]=> object(stdClass)#5111 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "B0IUUZ_4WJw" ["related_video_title"]=> string(186) "💥ГАЛЛЯМОВ: разведка Израиля проникла в бункер лидера Ирана! Даже опытные генералы ЦАХАЛа были в шоке" ["posted_time"]=> string(24) "11 часов назад" ["channelName"]=> string(31) "Телеканал Прямий" } [9]=> object(stdClass)#5129 (5) { ["video_id"]=> int(9999999) ["related_video_id"]=> string(11) "uUrpicDpiWs" ["related_video_title"]=> string(100) "Покушение на Зеленского / Предатель в Офисе президента" ["posted_time"]=> string(20) "21 час назад" ["channelName"]=> string(10) "NEXTA Live" } }
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

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 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

LLM и GPT - как работают большие языковые модели? Визуальное введение в трансформеры

LLM и GPT - как работают большие языковые модели? Визуальное введение в трансформеры

Но что такое нейронная сеть? | Глава 1. Глубокое обучение

Но что такое нейронная сеть? | Глава 1. Глубокое обучение

Долгожданный МИР. Или...

Долгожданный МИР. Или...

How to draw a multiple bar chart in R using ggplot2? | Contingency table | StatswithR | Arnab Hazra

How to draw a multiple bar chart in R using ggplot2? | Contingency table | StatswithR | Arnab Hazra

Закон сохранения энергии — величайшее заблуждение физики [Veritasium]

Закон сохранения энергии — величайшее заблуждение физики [Veritasium]

💥ГАЛЛЯМОВ: разведка Израиля проникла в бункер лидера Ирана! Даже опытные генералы ЦАХАЛа были в шоке

💥ГАЛЛЯМОВ: разведка Израиля проникла в бункер лидера Ирана! Даже опытные генералы ЦАХАЛа были в шоке

Покушение на Зеленского / Предатель в Офисе президента

Покушение на Зеленского / Предатель в Офисе президента

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



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



Контакты для правообладателей: [email protected]