Taking control of ggplot legends and colors for multiple seriesEmily Dolson10/07/2015ggplot is pretty good at figuring out what to put in your legend if the different classes that you’re plotting are spelled out in your data frame. For instance, the R built-in dataset
It’s usually a good idea to set your dataframes up this way, anyway, because it allows for you to operate on them flexibly. Sometimes, though, you just want to make a plot of two completely different series without smushing them together. For this example we will use the built-in
By default, the legend is given the same label as the first color. This isn’t usually what you want. You can set it with any of the
Sometimes, you might want to choose the values associated with each label. This can be accomplished with
Sometimes you don’t actually want to put all of the colors that you used on your legend. A common example of this is if you want to make open-circle markers for one of your data-sets. You can accomplish this by overlaying smaller circles of the background color onto larger circles of the desired outline color. If you want to do that to all circles of a given set, you can set the color outside of
But what if you want to make some circles open based on some attribute of a given data point? Everything that will vary by point needs to go in
You probably don’t want that. You can get rid of it by listing only the colors you want in the legend in the
Comments are closed.
|
Spatial Ecology @ MSUClick on "Category" below to search for R code compiled by the Zarnetske Spatial & Community Ecology Lab and students in MSU's Spatial Ecology graduate course (FOR870/FW870) Category
All
Archive
October 2016
|