![]() ![]() ![]() Notice that we're using the parameters nudge_x and nudge_y to pass in the offsets that we just created in the previous section. We'll add the state names with the state_names object we created earlier.Īnd we'll use geom_text_repel() to add the port names. We're going to use the base plot that we created earlier and saved with the name base_plot. So finally, we're going to put everything together. ,location = 'Port Sabine Pass, Texas' ~ -.5 ,location = 'Port Galveston, Texas' ~ -.5 ,location = 'Port Corpus Christi, Texas' ~ 0 ,y_nudge = case_when( location = 'Port Brownsville, Texas' ~ -1 ,location = 'Port of Orange, Texas' ~ 1.6 #,location = 'Port of Texas City, Texas' ~ 0 ,location = 'Port Corpus Christi, Texas' ~ 1.5 ,location = 'Port Mansfield, Texas' ~ 1.5 Mutate(x_nudge = case_when( location = 'Port Brownsville, Texas' ~ 1.3 Mutate(x_nudge = case_when( ID = 'Texas' ~ 1.3įrom here, we'll use geom_text() to create some labels that we can add to our plot, which we'll save as state_names. To do this, we’re going to use the ggplot theme function, and change specific plot elements. change the font size for the title, subtitle, and other text.Here, we’re going to create a “theme” that will format the plot elements of our chart. to create a theme to modify the fonts and colors.In the next step, we’ll make it look good. Geom_point(data = port_data, aes(x = long, y = lat), color = 'red') +Ĭoord_sf(xlim = c(-100, -92), ylim = c(25,33))Īgain … this is really rough around the edges, so to speak. You’ll need to run that code, because it has some of the building blocks that we need going forward.Īfter you run it, you can create our rough draft from part 1: Mutate(location_brief = str_replace(location, ', Texas', '')) ->Ĭoordinates = geo_osm(port_data$location) This code is very similar to the code in part 1, with a few minor modifications (e.g., I made some modifications to the port names, etc).Ĭoord_sf(xlim = c(-100, -91), ylim = c(25,33)) This week, we’re going to take that map and polish it up a little bit.įirst, you’ll need to run some preliminary code. That map was really just a “rough draft.” It’s not terrible, but it didn’t look great either. Last week in Mapping Texas Ports with R, we created a simple map of Texas ports with R, ggplot2, and geom_sf. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |