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

Показать описание
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:
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:
Комментарии