Created
October 20, 2020 22:42
-
-
Save JustinWenzhaoLi/eeb8c17ca83e99ae86aed00dce30b994 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Read Data: | |
| d = read.csv(file.choose(), header = TRUE) | |
| # Date suc has 4/1/2002, use "%m/%d/%y" | |
| d$Date<- as.Date(d$Date, "%m/%d/%y") | |
| # Group by Month | |
| Month <- format(d$Date, "%m") | |
| # Calculating the monthly anoamlies | |
| anom <- d$Values - ave(d$Values, Month, FUN = function(x) mean(x, na.rm = TRUE)) | |
| d$anom <- anom | |
| # Libraries | |
| library(ggplot2) | |
| library(dplyr) | |
| # Omit the NA to Make sure dots are connected | |
| d <- na.omit(d) | |
| # Most basic bubble plot | |
| p <- ggplot(d, aes(x=Date, y=anom)) + | |
| geom_line( color="steelblue") + | |
| geom_point() + | |
| ylim(-25,20) + | |
| ylab("mm") + | |
| xlab("date") + | |
| theme_bw() + | |
| theme(axis.text.x=element_text(angle=60, hjust=1)) | |
| p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment