Skip to content

Instantly share code, notes, and snippets.

@robwschlegel
Created June 12, 2017 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwschlegel/7bfbdbd29d77efac8cd7dc77754615b1 to your computer and use it in GitHub Desktop.
Save robwschlegel/7bfbdbd29d77efac8cd7dc77754615b1 to your computer and use it in GitHub Desktop.
ggplot(data = ERA_pixel, aes(x = date, y = y_axis)) +
# Here we create the wind vectors as a series of segments with arrow tips
geom_segment(aes(x = date, xend = date + u*wind_scale, y = 0, yend = v*wind_scale),
arrow = arrow(length = unit(0.15, 'cm')), size = 0.5, alpha = 0.7) +
# I think adding points at the base of the vectors makes the figure easier to read
geom_point(aes(x = date, y = 0), alpha = 0.5, size = 1) +
# Changing the dates to better match the range shown on the x axis
scale_x_date(labels = date_format('%Y-%m-%d'), breaks = date_breaks('4 days')) +
# Change the y axis labels to make sense
scale_y_continuous(breaks = y_axis, labels = as.character(abs(y_axis)/wind_scale)) +
# Change the x and y axis labels
labs(x = NULL, y = 'Wind Speed (m/s)') +
coord_equal(ylim = c(min(y_axis/wind_scale), max(y_axis/wind_scale))) +
theme(axis.text.x = element_text(angle = 20, hjust = 0.4, vjust = 0.5, size = 8),
axis.text.y = element_text(size = 8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment