In this vignette, I’d like to explain how to use guide_colourbar()
function to control color bar.
If you are not familiar with the R package ggplotAssist, please read the following REAME file of the ggplotAssist
package.
https://cran.r-project.org/web/packages/ggplotAssist/README.html
You can install developmental version of ggplotAssist
package from github.
#install.packages("devtools")
devtools::install_github("cardiomoon/ggplotAssist")
You can see help file for guide_colourvar() function by typing ?guide_colourbar
in R console. This function has so many arguments.
guide_colourbar(title = waiver(), title.position = NULL,
title.theme = NULL, title.hjust = NULL, title.vjust = NULL,
label = TRUE, label.position = NULL, label.theme = NULL,
label.hjust = NULL, label.vjust = NULL, barwidth = NULL,
barheight = NULL, nbin = 20, raster = TRUE, ticks = TRUE,
draw.ulim = TRUE, draw.llim = TRUE, direction = NULL,
default.unit = "line", reverse = FALSE, order = 0, ...)
We are going to make this plot.
require(ggplot2)
df <- reshape2::melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
ggplot(df, aes(X1, X2)) +
geom_tile(aes(fill = value)) +
guides(fill = guide_colorbar(barwidth = 0.5, barheight = 10, title="Value"))
df <- reshape2::melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
Turn on the preprocessing(2). Enter df
as a data name(3). Select x
among Aesthetics
and select
X1 among mapping
. And then select y
and X2
to make R code for ggplot(5).
Select geom
among layers(1). Select geom_tile
function(2). Select mapping
radioButton(3). Select fill
among aesthetics(4) and assign value
(5). Confirm the R code for layer(6) and press Add Layer
button(7).
Select guides
among layers(1). Select guides
function(2). Select fill
aesthetics(3). select guide_colorbar
among fill selectInput(4). You can see the arguments of the function guide_colourbar()(scarlet rectangle). Enter 0.5
as barwidth(5) and 12
as barheight(6). Enter Value
as title(7). You can see the R code for this layer(8).
You can see the plot preview. Please compare colorbars of two figures.
Please do not hesistate to change the arguments of this function guide_colourbar()
with your mouse. Happy ggplot!!