1

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")

enter image description here enter image description here

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)

enter image description here

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.

4
  • 2
    Please don't delete your old questions, especially if they have helped you, which it looks like they have.
    – Spacedman
    Jan 17 at 11:15
  • This might require three steps back to go this one step forward. When you save a PNG with ggsave it doesn't save any coordinate information, so the georeferencing is lost, and when you read it back with readImage 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...
    – Spacedman
    Jan 17 at 11:20
  • Another possibility is to stick with the summed images, and the re-assign the georeferencing information. For this you need to know the exact coordinates of at least two points on the map in whatever coordinate system the map is projected in, or the exact coordinates of the pixels at the top, bottom, and sides of the image, but this is complicated by the embedding of the plot into a graphic device which means there might be borders and padding (the grey bits, perhaps).
    – Spacedman
    Jan 17 at 11:22
  • @Spacedman I appreciate your help with this problem. Next time, I won't delete the question. Yes, I would like to solve everything with ggplot, but so far I have not succeeded. Jan 17 at 20:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.