Give me R code that creates a simple chloropleth map of the US with random generated data.
- User
Give me R code that creates a simple chloropleth map of the US with random generated data.
Assistant
Sure! Here's some R code that creates a simple chloropleth map of the US with random generated data:
# Load the required libraries library(rgeos) library(rgdal) library(rworldmap) # Generate some random data for the map state_data <- data.frame( state = names(states), value = runif(50, 1, 100) ) # Convert the data to a SpatialDataFrame state_sf <- state_data |> spatial::sp_polygons(id = "state", polygon = states) |> sf::st_set_geometry() # Create a chloropleth map gg <- ggplot(state_sf, aes(x = long, y = lat, fill = value)) + geom_polygon() + scale_fill_gradient(low = "blue", high = "red") + labs(title = "Random Data Chloropleth Map of the US") gg
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.