Modify Scientific Notation on ggplot2 Plot Axis in R | Change Labels | scales & stringr Packages

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

library("ggplot2") # Load ggplot2 package

ggp <- ggplot(data, aes(x = x)) + # Create ggplot2 plot with default axes
geom_density()
ggp # Draw ggplot2 plot with default axes

library("scales")

ggp + # Modify axes using scales package
scale_x_continuous(labels = unit_format(unit = "e+06", scale = 1 / 1e+06, digits = 2))

library("stringr")

formatCustomSci <- function(x) { # Create user-defined function
x_sci <- str_split_fixed(formatC(x, format = "e"), "e", 2)
paste(alpha * 10, power - 1L, sep = "e")
}

ggp + # Modify axes using user-defined function
scale_x_continuous(labels = formatCustomSci)

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Carry on sir don't stop uploading videos

rockstargamer
visit shbcf.ru