height <- seq(0, 100*1000, by = 1*200)
# Temperature profile that defines the standard atmosphere (in degrees Celsius)
plot(sa_temperature(height) - 273.15, height, type = "l")
# Pressure profile
plot(sa_pressure(height), height, type = "l")
# Use with ggplot2
library(ggplot2)
data <- data.frame(height = height/1000, # height in kilometers
pressure = sa_pressure(height)/100) # pressures in hectopascals
# With the sa_*_axis functions, you can label the approximate height
# when using isobaric coordinates#'
ggplot(data, aes(height, pressure)) +
geom_path() +
scale_y_continuous(sec.axis = sa_height_axis("height"))
# Or the approximate pressure when using physical height
ggplot(data, aes(pressure, height)) +
geom_path() +
scale_y_continuous(sec.axis = sa_pressure_axis("level"))
# When working with isobaric coordinates,using a linear scale exagerates
# the thickness of the lower levels
ggplot(temperature[lat == 0], aes(lon, lev)) +
geom_contour_fill(aes(z = air)) +
scale_y_reverse()
# Using the standard atmospehre height transormation, the result
# is an approximate linear scale in height
ggplot(temperature[lat == 0], aes(lon, lev)) +
geom_contour_fill(aes(z = air)) +
scale_y_continuous(trans = "sa_height", expand = c(0, 0))
# The result is very similar to using a reverse log transform, which is the
# current behaviour of scale_y_level(). This transformation slightly
# overextends the higher levels.
ggplot(temperature[lat == 0], aes(lon, lev)) +
geom_contour_fill(aes(z = air)) +
scale_y_level()
Run the code above in your browser using DataLab