
You’ve assigned the size using the size_scale_manual() function.Note that similar to colors, you have adjusted the lines using two steps However it’s better to be explicit and set which attribute value should be associated with each line width. Similar to the colors set above, ggplot() will apply the line width in the order of the factor levels in the data. Here you use scale_size_manual() to set the line width for each category in the RTTYP attribute. If you want a unique line width for each factor level or attribute category in your spatial object, you can use a similar syntax to the one you used for colors. # size adjusts the line widht ggplot () + geom_path ( data = sjer_roads_df, aes ( x = long, y = lat, group = group, color = factor ( RTTYP )), size = 1.1 ) + scale_colour_manual ( values = road_palette ) + labs ( title = "Madera County Roads ", subtitle = "With big fat lines!", color = "Road type", x = "", y = "" ) + theme ( axis.text = element_blank (), axis.ticks = element_blank ()) + coord_fixed () Customize the legend title using labs( color =).Remove the x and y labels using the x = and y = arguments in the labs() function.Remove the x and y axis ticks and label using the theme argument.You can customize any element of the plot including fonts, colors and more! Themes are used in ggplot() to customize the look of a plot. Remove ggplot Axis Ticksįinally you can remove the axis ticks and labels using a theme() element. Notice that above the colors are applied to each category (C, M, S and Unknown) in order. # count the number of unique values or levels length ( levels ( sjer_roads $ RTTYP )) # 0 # create a color palette of 4 colors - one for each factor level road_palette <- c ( "C" = "green", "M" = "grey40", "S" = "purple", "Unknown" = "grey" ) road_palette # C M S Unknown # "green" "grey40" "purple" "grey" # plot with custom colors # size adjusts the line width ggplot () + geom_path ( data = sjer_roads_df, aes ( x = long, y = lat, group = group, color = factor ( RTTYP ))) + scale_colour_manual ( values = road_palette ) + labs ( title = "Madera County Roads ", subtitle = "Colored by road type" ) The process isn’t bad once you have the steps down! Let’s check it out.ĭata Tip: If your data attribute values are not read in as factors, you can convert the categorical attribute values using as.factor().įirst, let’s import all of the needed libraries. However, you will have to convert your data from spatial ( sp) objects to ames to use ggplot. Compared to base plot, you will find creating custom legends to be simpler and cleaner, and creating nicely formatted themed maps to be simpler as well. ggplot is a powerful tool for making custom maps. In this lesson you will create the same maps, however instead you will use ggplot(). In the previous lesson, you used base plot() to create a map of vector data - your roads data - in R. You will need a computer with internet access to complete this lesson and the data for week 4 of the course.ĭownload Week 4 Data (~500 MB) Making Maps with GGPLOT Plot a vector dataset by attributes in R using ggplot().SECTION 15 LAST CLASS: FINAL PROJECT PRESENTATIONSĪfter completing this tutorial, you will be able to:.SECTION 14 FINAL PROJECTS & COURSE FEEDBACK DISCUSSION.SECTION 10 MIDTERM REVIEW / PRESENTATION BEST PRACTICES.


