1/12/2024 0 Comments Ggplot2 scatter plot two seriesGgplot(groupSummaries, aes(month, N, colour = )) + However, we are going to perform the highlighting with gghighlight vs manual layering. Using ggplot2, create a plot with your full data set.Īdd the gghighlight() function to your plot with the conditions set to identify your subset.Ĭelebrate! This was one less step AND we got labels!įor our first example, we are going to create the same time series graph from above. Thanks to Hiroaki Yutani, we now have the gghighlight package which does most of the work for us with a small function call!! Please note that a lot of this code was created by looking at examples on her introduction document. Further, you have to tinker more with the labelling to really call out the highlighted data points. While the above methodology is quite easy, it can be a bit of a pain at times to create and add the new data frame. Highlighting Your Data in R: The New School Way ![]() Theme(legend.position="bottom",legend.text=element_text(size=7), Ggplot(groupSummaries, aes(x=month, y=N, color=) )+ #Group the data into a new data frame which has the count of events per month by subgroup # Create some color variables for graphing laterĬreate a basic time series plot showing the count of 911 event types by month. Install and Load Libraries install.packages("lubridate")ĭownload the Data incidents= fread('', stringsAsFactors = FALSE) If you'd like to get started with R in IBM Watson Studio, please have a look at the tutorial I wrote. Or we can use a free, hosted, multi-language collaboration environment like Watson Studio. We can use something like R Studio for a local analytics on our personal computer. In terms of setting up the R working environment, we have a couple of options open to us. Note that I have covered this data set through multiple blog posts already such as map plots in R and time based heat maps. Set the color to something other than grey.įor our example, we are going to examine the crime incident dataset from Seattle 911 Calls on. ![]() Using ggplot2, create a plot with your full data set in grey.Ĭreate a new data frame that has been subset to only include the data which you would like to highlight.Īdd the highlighted data on to your plot created in step 1. To implement this idea, we don't need any fancy packages other than ggplot2. Highlighting Your Data in R: The Old School Way
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |