I am making a function for easily save my plots. I wrote the function as follows:
Cases07 <- plot_usmap(data = data, values = "case2107_rate1000", regions = "county") +
scale_fill_manual(values = cols, labels=label, na.value="grey", drop = FALSE)+
labs(title ="Cases per 1000") +
guides(fill=guide_legend(title="Cases per 1000")) + thm
#Here is the plot saving function
savemap <- function(x){
png(paste(deparse(substitute(x)),".png",sep = ""),width = 1200, height =900, units = "px")
x
dev.off()
}
However, this doesn't work.
savemap(Cases07). #This does not save my plot as expected.
But, either
savemap <- function(x){
paste(deparse(substitute(x)),".png",sep = "")
}
#This outputs "Cases07.png".
or
savemap <- function(x){
x
}
#This plots the map.
worked as expected.
The original function does not save my plot. Anyone knows why this happens?