Setting graph axis limits and expanding plotting region in ggplot2Laura TwardochlebSeptember 14, 2016I demonstrate how to change axis limits and expand the plotting region in ggplot2, so that the plot origin lines up with the axis limits in a bar graph. The default graphic settings in ggplot2 produce bar graphs with the origin offset from the limits of the plotting region. We can visualize this using the built in “cars” dataset:
Above you can see that there is a gap between the plotting region on the lower y-axis and the origin (y=0). However, this graph will be more aesthetically pleasing and easier to read if the axis limits and plotting region both begin at the origin. To change this, we can add one line of code to change the limits of the y-axis and expand the plotting region to begin at the origin (y=0).
Here, I used
0 Comments
R Tip: Code shortcut when adding new layers in GGPLOT2September 12, 2016Creating a new plot can involve a lot of trial and error when it comes to adding layers and changing aesthetics to make the plot look just right. This could result in one typing the same commands over and over again. This shortcut demonstrates how to create an object containing different layers that can be recalled more quickly. The example is code using ggplot(). Diamond carat will be plotted on the x-axis and Price on the y-axis. Data points will be colored differently according to diamond clarity. This R tip is modified from html.http://rstudio-pubs-static.s3.amazonaws.com/3355_d3f08cb2f71f44f2bbec8b52f0e5b5e7.html
Package: RColorBrewerSeptember 7, 2016ColorBrewer is an R packages that can assist you in choosing your colour schemes for figures in R. For example if you are making an x-y plot that has multipe lines, what colours could you use so you can easily identify the lines?
|
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
|