Pergunta

I am looking to plot the temperatures of different cities of Virginia using maps in R I have the following variables with me for all the cities in my dataset.

Name of city, Latitude, Longitude, Temperature

Do I need additional variables or packages to show the temperatures.

Do I need to create an adjacency matrix or what functions should I be searching for to do this?

My end goal is to show the temperatures on the map with the corresponding city names.

Foi útil?

Solução

Assuming your data is in a data.frame called tempdat, you could use the following code to put the temperature as text at each point:

library(maps)
map("state", "Virginia")
text(tempdat$long, tempdat$lat, label=tempdat$temperature)

For example, you could create tempdat by filtering the list of US cities built into the maps package for those in Virginia, then adding random temperatures:

data(us.cities)
tempdat= us.cities[us.cities$country.etc == "VA", ]
tempdat$temperature = round(rnorm(nrow(tempdat), mean=75, sd=5))

At which point the plot would look something like this (it's far too crowded, so if your set of cities are this crowded you may want to plot the temperature using color rather than text. Anything you can do with the points function built into R, you can do here).

enter image description here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top