sarahtanja / anemone-leachate

This science experiment tests the photobiology, microbiome, and gene expression responses of the aggregating sea anemone to plastic pollutant derived leachate
1 stars 0 forks source link

Text mods in ggplot2 #6

Open sarahtanja opened 6 months ago

sarahtanja commented 6 months ago

`# Load ggplot2 library(ggplot2)

Create a sample plot

p <- ggplot(mpg, aes(x = displ, y = hwy, color = class)) + geom_point() + labs( title = "Fuel Efficiency", x = "Engine Displacement (L)", y = "Highway Miles per Gallon", color = "Car Class" )

Adjust text sizes using theme()

p + theme( plot.title = element_text(size = 20, face = "bold"), # Title text size axis.title.x = element_text(size = 16), # X-axis title text size axis.title.y = element_text(size = 16), # Y-axis title text size axis.text.x = element_text(size = 14), # X-axis text size axis.text.y = element_text(size = 14), # Y-axis text size legend.title = element_text(size = 16), # Legend title text size legend.text = element_text(size = 14) # Legend text size ) `

sarahtanja commented 6 months ago

Scale Transformation in ggplot

Load ggplot2

library(ggplot2)

Create sample data

data <- data.frame( x = 1:10, y = runif(10, min = 0, max = 1e-5) )

Create the plot

p <- ggplot(data, aes(x = x, y = y)) + geom_point() + labs( y = expression("Rate (mg/min) x"~10^-5), x = "Time (min)", title = "Rate over Time" ) + scale_y_continuous( labels = function(x) x / 1e-5 # Transform the y-axis labels )

Print the plot

print(p)