View source: R/geom-sidesegment.r
geom_xsidesegment | R Documentation |
The xside and yside of geom_segment.
geom_xsidesegment( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., arrow = NULL, arrow.fill = NULL, lineend = "butt", linejoin = "round", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_ysidesegment( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., arrow = NULL, arrow.fill = NULL, lineend = "butt", linejoin = "round", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
arrow |
specification for arrow heads, as created by |
arrow.fill |
fill colour to use for the arrow head (if closed). |
lineend |
Line end style (round, butt, square). |
linejoin |
Line join style (round, mitre, bevel). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
XLayer or YLayer object to be added to a ggplot object
library(dplyr) library(tidyr) library(ggdendro) #dendrogram with geom_*sidesegment df0 <- mutate(diamonds, colclar = interaction(color, clarity, sep = "_", drop = TRUE)) df1 <- df0 %>% group_by(color, clarity, colclar, cut) %>% summarise(m_price = mean(price)) df <- df1 %>% pivot_wider(id_cols = colclar, names_from = cut, values_from = m_price, values_fill = 0L) mat <- as.matrix(df[,2:6]) rownames(mat) <- df[["colclar"]] dst <- dist(mat) hc_x <- hclust(dst) lvls <- rownames(mat)[hc_x$order] df1[["colclar"]] <- factor(df1[["colclar"]], levels = lvls) dendrox <- dendro_data(hc_x) p <- ggplot(df1, aes(x = colclar, cut)) + geom_tile(aes(fill = m_price)) + viridis::scale_fill_viridis(option = "magma") + theme(axis.text.x = element_text(angle = 90, vjust = .5)) p + geom_xsidesegment(data = dendrox$segments,aes(x = x, y = y, xend = xend, yend = yend))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.