Город МОСКОВСКИЙ
00:04:33

Add Values to Heatmap in R (Example) | How to Draw Numbers in Cells | ggplot2 & geom_text() Functio

Аватар
Python: Изменение в практике программирования
Просмотры:
28
Дата загрузки:
02.12.2023 18:21
Длительность:
00:04:33
Категория:
Обучение

Описание

How to draw a heatmap with values in the R programming language. More details: https://statisticsglobe.com/add-values-heatmap-r
R code of this video:

set.seed(328576) # Create example data
data <- data.frame(group1 = rep(LETTERS[1:4], each = 10),
group2 = letters[1:10],
values = round(rnorm(40), 2))
head(data) # Print head of example data

install.packages("ggplot2") # Install & load ggplot2
library("ggplot2")

ggp <- ggplot(data, aes(group1, group2)) + # Create default ggplot2 heatmap
geom_tile(aes(fill = values))
ggp # Draw default ggplot2 heatmap

ggp + # Add values to heatmap
geom_text(aes(label = values))

ggp + # Add values & modify color
geom_text(aes(label = values)) +
scale_fill_gradient(low = "white", high = "#1b98e0")

Follow me on Social Media:
Facebook – Statistics Globe Page: https://www.facebook.com/statisticsglobecom/
Facebook – Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe
LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/
LinkedIn – Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/
Twitter: https://twitter.com/JoachimSchork

Music by bensound.com

Рекомендуемые видео