- Subscribe via RSS
Word Cloud LinksAnimation (3) CSP (3) Data (22) Data Science (6) Distributions (1) Dust (7) Economics (15) Engineering (11) Equipment Vendors (3) Faster R (2) GDAL (5) Germany (1) ggplot2 (20) GIS (5) Irradiance (17) Kuwait (1) LaTeX (11) Linux (2) Meteorology (16) Misc Tricks (3) Modeling (9) Natural Gas (2) Nuclear (1) O&M (2) Projects (5) Project Valuations (6) Qatar RE (13) R Colors (9) R Data Import (6) R Data Objects (16) R Data Syntax (6) Renewable Energy (14) RE Policy (7) Resource Assessment (19) R Graphics (19) R Packages (3) R Programming (22) Saudi Arabia (3) Scientific Computing (1) Solar (39) Spatial Analysis (6) Storage (3) UAE (4) Ubuntu (1) Website (4) WECC (3) Wind (5)
Category Archives: ggplot2
There are number of ways to control the default colors in ggplot.
The HCL Color Wheel
ggplot simplifies color choice with its default color selection, which are based on a “color wheel.” The result is a well balanced graphic that doesn’t draw too much attention to any one color. ggplot uses the HCL color wheel and the hue_pal() function from the scales package. Specifically, if there are two colors, then they will be selected from opposite points on the circle; if there are three colors, they will be 120° apart on the color circle; and so on. This ensure that discrete data has maximum contrast as a function of the number variables present.
Legends are a key component of data visualization. ggplot format controls are defined below.
The diamonds data that ships with ggplot.
The Default Legend
The following example presents the default legend to be cusotmized.
def <- ggplot(diamonds, aes(cut, price)) + geom_boxplot(aes(fill = factor(cut))) +
labs(title = "Diamonds Data", x = "Cut", y = "Price (USD)")
Click to enlarge
Removing the Legend
Legends are created for different aesthetics, such as fill, color/colour, linetype, shape, etc. Each aesthetic has a scale function than can be called to remove the legend:
Robert Hyndman is the author of the forecast package in R. I’ve been using the package for long-term time series forecasts. The package comes with some built in methods for plotting forecast data objects in R that Ive wanted to customize for improved clarity and presentation. The following article achieves that goal and shares two scripts for plotting forecast data objects using ggplot.
The levelized cost of energy (LCOE) is presented by region and for different power generation technologies. The simple model ignores the impact of subsidies, financing and tax impacts to focus on relative performance by technology.
The LCOE data is compared to annual average power prices. In practice, price levels can vary over wide ranges, especially given winter weather. Several noteworthy conclusions are evident when average prices are used:
The standard function for correlation plots in R is pairs(), which generates a matrix of scatter plots based on all pairwise combinations of variables in a data object. The standard graph looks something like this after a little color enhancement:” Click to enlarge
The code behind this plot is simple:
main = "Anderson's Iris Data",
pch = 21,
bg = c("red", "green2", "steelblue4")[unclass(iris$Species)])