I need transpose Wind Rose onto Map by image addition. I attempt to implement this code:
particolato <- read.csv('Acri_PM.csv')
Rose <- subset(particolato, wd != "") #remove blank records
Rose <- factor(Rose$wd) #save changes made by subset
Rose <- factor(Rose, levels = c("N","NNE", "NE", "ENE",
"E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW",
"W", "WNW", "NW", "NNW"))
WindRose1 <- ggplot(data.frame(Rose), aes(x=Rose, fill=Rose))+
geom_bar(stat="count",width=1,colour="black",size=0.1, alpha= 0.5)+
coord_polar(theta = "x", start=6.0729, direction = 1)+
scale_color_discrete ()+
ggtitle("Frequency Wind Rose", subtitle= "2014 - 2020, Acri (CS)") +
xlab("Wind Direction Recorded Every Day")+
ylab("")+
guides(fill=guide_legend(title="Direction")) +
theme(plot.title = element_text(size=18, face= "bold", color = "red"),
axis.title.x = element_text(size= 7), axis.text.y=element_blank(),
axis.ticks.y = element_blank())
WindRose1
WindRose2 <- ggplot(data.frame(Rose), aes(x=Rose, fill=Rose))+
geom_bar(stat="count",width=1,colour="black",size=0.1, alpha= 0.5)+
coord_polar(theta = "x", start=6.075, direction = 1)+
scale_color_discrete ()+ ggtitle("Frequency Wind Rose")+
xlab("Wind Direction Recorded Every Day")+
ylab("")+
guides(fill=guide_legend(title="Direction")) +
theme(plot.title = element_text(size=18, face= "bold",
color = "burlywood1",
vjust = -3, hjust = -0.15),
axis.title.x = element_text(size= 8, color = "cornsilk1",
hjust = 1.05, vjust = 1.4),
axis.text.y=element_blank(), axis.ticks.y = element_blank(),
axis.text.x = element_text(colour = "cornsilk2", size= 12, face = "bold"),
legend.position = "none")+
theme(panel.grid.major = element_line(colour = NA),
axis.line = element_line(colour = NA),
plot.background = element_rect(fill= "transparent", colour= NA),
panel.background = element_rect(fill= "transparent", colour = NA))
WindRose2
ggsave(WindRose2, file="WindRose2.png", bg= "transparent", device = NULL)
Acri <- get_map(location= c(lon= 16.3868, lat= 39.48963), zoom = 17, maptype = "hybrid")
Map_Acri <- ggmap(Acri, extent = "device")
Map_Acri
ggsave(Map_Acri, file= "Map_Acri.png", device = NULL)
WindRose2_png <- readImage("~/R Language/WindRose2.png")
Map_Acri_png <- readImage("~/R Language/Map_Acri.png")
Practically it is necessary to superimpose one graph on another. They have same shapes, because saved 5.86 x 4.02 in image.
> dim(WindRose2_png)
[1] 1206 1759 4
> dim(Map_Acri_png)
[1] 1206 1759 3
WindRose2_png has four layers and Map_Acri_png only has three.
WindRose2_png <- readImage("~/R Language/WindRose2.png")
Map_Acri_png <- readImage("~/Map_Acri.png")
WindRoseMap <- (WindRose2_png[,,1:3] + Map_Acri_png)
imageShow(WindRoseMap)
How to draw point (point of my analysis) on map with R?
CC <- points(16.44529,39.495616,pch=16,col="red")
this code does not give any result.
ggsave
it doesn't save any coordinate information, so the georeferencing is lost, and when you read it back withreadImage
you get an NxM matrix located at (0,N) x (0,M). Unless you need the graphics separately, might it not be easier to do the whole plot in one ggplot graphic, with the map and the wind rose? You might need to do some coordinate calculations but all this image manipulations isn't the best way to do things...ggplot
, but so far I have not succeeded.