library ( tidyverse )
-library (
+Code
+palmerpenguins library (tidyverse)
+)
-
-library (palmerpenguins)
+
+set.seed set.seed (( 123 )
+
+mtcars 123 <- mtcars )
-
-|>
+ mtcars rownames_to_column (<- var = mtcars "name" ) |>
- |>
+ rownames_to_column as_tibble () ( var |>
+ = sample_n ("name" 20 )
+
+penguins ) <- penguins |>
- as_tibble filter (( complete.cases (penguins))
+
+p1 ) <- |>
- ggplot (mtcars, sample_n aes (wt, mpg, ( label = name)) 20 +
+ )
-
-geom_point (penguins color = <- "cyan4" , penguins size = |>
- 2 )
+p1
+p2 filter <- ( ggplot (penguins, complete.cases aes (( x = bill_length_mm, penguins y = bill_depth_mm)) ) +
+ )
-
-geom_point (p1 aes (<- color = species), ggplot size = ( 2 )
+p2
+p3 mtcars , <- penguins aes |>
+ ( count (species) wt , |>
+ mpg , label ggplot (= aes (species, n)) name +
+ ) geom_col ()
+p3
+
+
+In my particuar case I like theme_minimal
theme and legend at the bottom.
+
+
+Code
+) theme_set (
+ theme_minimal () +
- geom_point theme (
+ ( color plot.title = = element_text ("cyan4" , size face = = "plain" ),
+ 2 plot.background = )
-element_rect (p1
-fill = p2 "#fcfcfc" , <- colour = ggplot NA ),
+ ( panel.background = penguins , element_rect (aes fill = ( x "#fcfcfc" , = colour = bill_length_mm , y NA ),
+ = legend.position = bill_depth_mm "bottom" ,
+ ) legend.key.width = ) unit (+
- 1.5 , geom_point "cm" )
+ )
+)
+
+colors ( <- aes c (( color "darkorange" ,= "darkorchid" ,species "cyan4" )
+
+
+We’re ready to go!
+
+{showtext}
+Source:https://github.com/yixuan/showtext .
+This package makes easy to use typography! Do you want some typography from https://fonts.google.com/? You want it? You got it!
+
+
+Code
+) , size library (showtext)
+
+= font_add_google (2 "IBM Plex Sans" , )
-family = p2
-"ibm" )
+
+p3 showtext_auto ()
+
+p2
+
+
+
+
+
+
+
+
+
+
+
+{ggrepel}
+Source: https://ggrepel.slowkow.com/articles/examples.html .
+This package has been on CRAN/github for a while now. Package that in combination with the data
argument can make simple and effective annotations.
+
+
+Code
+<- library (ggrepel)
+
+p_repel1 penguins <- p1 |>
- +
+ count geom_text_repel (( color = species "gray40" , ) family = |>
- "ibm" )
+
+p_repel1
+
+
+
+
+
+
+
+
+
+Code
+p_repel2 ggplot <- p1 ( +
+ aes geom_text_repel (
+ ( data = species , ~ n filter (.x, mpg ) > ) 30 ),
+ +
- color = geom_col "gray40" ,
+ ( family = )
-"ibm" ,
+ p3
-
-
-
-
-
-
-
-
-
-
-
+font-style: inherit;">force =
20
+
)
+
+
p_repel2
+
+
+
+
+
+
-
In my particuar case I like theme_minimal
theme and legend at the bottom.
+
+
+{gghighlight}
+Source: https://yutannihilation.github.io/gghighlight/articles/gghighlight.html .
+
+This package is plug and play if you have to highlight data with a specific filter.
+Is important to know this package don’t work like the usual geom_*
+ aes()
.
+
-
Code
+Code
+theme_set library (gghighlight)
+
+p1 (
- +
+ theme_minimal gghighlight (
+ ( # interest subset
+ mpg ) > +
- 30 ,
+ theme # additional parameters
+ (
- plot.title label_key = name,
+ = keep_scales = element_text TRUE ,
+ ( face label_params = = list ("plain" color = ) ,
- plot.background "gray40" , = label.r = element_rect ( fill = "#fcfcfc" , colour = NA ) ,
- panel.background = element_rect ( fill = "#fcfcfc" , colour = NA ) ,
- legend.position = "bottom" ,
- legend.key.width = unit ( 1.5 , "cm" )
- )
-0 , )
-
-fill = colors "gray95" ),
+ <- # can change previous parameters
+ c unhighlighted_params = ( list ("darkorange" ,size = "darkorchid" ,1.5 , "cyan4" color = )
+font-style: inherit;">"darkorchid" )
+ )
+
+
+
+
+
-
We’re ready to go!
-
{showtext}
-Source:https://github.com/yixuan/showtext .
-This package makes easy to use typography! Do you want some typography from https://fonts.google.com/? You want it? You got it!
-
-
Code
-
-
-
-
-{ggrepel}
-Source: https://ggrepel.slowkow.com/articles/examples.html .
-This package has been on CRAN/github for a while now. Package that in combination with the data
argument can make simple and effective annotations.
-
-
Code
-
-
-
-
Code p_repel2 <- p1 +
- geom_text_repel (
- data = ~ filter ( .x , mpg > 30 ) ,
- color = "gray40" ,
- family = "ibm" ,
- force = 20
- )
-
-p_repel2
-
-
-
+
+{ggforce}
+Source: https://ggforce.data-imaginist.com/ .
-This package is plug and play if you have to highlight data with a specific filter.
-Is important to know this package don’t work like the usual geom_*
+ aes()
.
+{ggforce}
takes annotations to the next level.
+A lot of other functionalities like new geoms, new facets!
-
Code library ( gghighlight )
-
-
+Code
+p1 library (ggforce)
+
+p1 +
- gghighlight (
- # interest subset
- mpg > 30 ,
- # additional parameters
- label_key = name ,
- keep_scales = TRUE ,
- label_params = list ( color = geom_mark_hull (
+ "gray40" , label.r aes (= filter = mpg 0 , fill > = 30 , "gray95" label = ) ,
- "Interesting" ),
+ # can change previous parameters
- unhighlighted_params description = = "Lightweight vehicles have high performance." ,
+ list color = ( size "gray70" ,
+ = fill = 1.5 , color "gray90" ,
+ = concavity = "darkorchid" )
- )
-
-
-
-
-{ggforce}
-Source: https://ggforce.data-imaginist.com/ .
-
-
-ggforce takes annotations to the next level.
-A lot of other functionalities like new geoms, new facets!
-
-
-
Code library ( ggforce )
-
-p1 +
- geom_mark_hull (
- aes ( filter = mpg > 30 , label = "Interesting" ) ,
- description = "Lightweight vehicles have high performance." ,
- color = "gray70" ,
- fill = "gray90" ,
- concavity = 5 ,
- 5 ,
+ # control width text
- label.minwidth = unit ( 100 , "mm" ) ,
- # how much distance before show legend
- label.buffer = unit ( 2.5 , "mm" ) ,
- label.colour = "gray30" ,
- label.family = "ibm"
- ) +
- # use circle for points
- geom_mark_circle (
- aes ( filter = wt > 3.75 , label = NULL , description = name ) ,
- color = "gray70" ,
- fill = "transparent" ,
- label.fontsize = 10 ,
- label.family = "ibm"
- )
-
-
-
-
-And other geom_mark_*
like hull, circle, ellpse, rect.
-
-
Code p2 +
- geom_mark_ellipse (
- aes ( fill = species , label = species ) ,
- alpha = 0.1 ,
- color = "transparent" , # a nice touch sometimes! (imho)
- label.colour = "gray30" ,
- label.family = "ibm" ,
- label.fontsize = 8 ,
- # label.fontface = "plain",
- # this is just for blogpost
- expand = unit ( - 5 , "mm" ) ,
- radius = unit ( 5 , "mm" )
- ) +
- geom_mark_circle (
- aes (
- filter = coalesce ( bill_length_mm , 0 ) == max ( bill_length_mm , na.rm = TRUE ) ,
- label = NULL ,
- description = "A rare penguin!"
- ) ,
- color = "gray70" ,
- fill = "transparent" ,
- label.fontsize = 8 ,
- label.family = "ibm"
- ) +
- theme ( legend.position = "none" ) +
- labs ( x = NULL , y = NULL )
-
-
-Now imagine we used a -means algorithm:
-
-
Code
-
-
# A tibble: 3 × 3
- bill_length_mm bill_depth_mm cluster
- <dbl> <dbl> <chr>
-1 38.8 18.4 1
-2 49.6 18.4 2
-3 47.4 15 3
-
-
Code bnd <- penguins |>
- summarise (
- min ( bill_length_mm , na.rm = TRUE ) - 1 ,
- max ( bill_length_mm , na.rm = TRUE ) + 1 ,
- min ( bill_depth_mm , na.rm = TRUE ) - 1 ,
- max ( bill_depth_mm , na.rm = TRUE ) + 1
- ) |>
- as.list ( ) |>
- unlist ( ) |>
- as.vector ( )
-
-p2 +
- geom_voronoi_tile (
- aes ( fill = cluster , group = - 1 ) ,
- data = dcenters , alpha = 0.2 , bound = bnd
- ) +
- geom_voronoi_segment (
- aes ( group = - 1 ) ,
- data = dcenters , color = "gray90" , bound = bnd
- ) +
- xlim ( bnd [ 1 ] , bnd [ 2 ] ) +
- ylim ( bnd [ 3 ] , bnd [ 4 ] ) +
- scale_fill_viridis_d ( direction = - 1 , option = "C" ) +
- # its better put point over all layers
- geom_point (
- aes ( color = species ) ,
- size = 2 ,
- shape = 21 ,
- color = "gray90"
- ) +
- theme ( legend.position = "right" )
-
-
-{ggfittext}
-Source: https://github.com/wilkox/ggfittext .
-This package have a lot of features to work with strings in ggplot objects, particulary when you use treemaps.
-A love the simple and useful function geom_bar_text()
+ geom_col()
combo.
-
-{scales}
-Source: https://scales.r-lib.org/ .
-You use this package using a label_*
function in the labels
argument of scale_*
function.
-
-
Code
-
-
[1] "123" "456,678" "100,000" "$123" "$456,678" "$100,000"
-
-
Code # I know the correct alternative is Mpg
-miles_per_gallon <- label_comma ( suffix = " mi/gal" )
-
-wt_lbl <- label_comma ( scale = 1000 , suffix = " lbs" )
-
-p1 +
- scale_y_continuous (
- labels = miles_per_gallon ,
- name = "fuel consumption"
- ) +
- scale_x_continuous (
- labels = wt_lbl ,
- name = "weigth"
- )
-
-
-
-
-{ggparty}
-Source: https://github.com/martin-borkovec/ggparty .
-
-
Code library ( partykit ) # ctree
- library label.minwidth = ( unit (ggparty 100 , )
-
-"mm" ),
+ penguinct # how much distance before show legend
+ <- label.buffer = ctree unit ((
- 2.5 , species "mm" ),
+ ~ label.colour = bill_length_mm "gray30" ,
+ + label.family = bill_depth_mm "ibm"
+ ) + +
+ flipper_length_mm # use circle for points
+ + geom_mark_circle (
+ body_mass_g aes (+ filter = wt sex ,
- data > = 3.75 , penguins
- label = )
-
-NULL , autoplot description = name),
+ ( color = penguinct "gray70" ,
+ )
-
-
-
-
-
-
Code fill = ggparty "transparent" ,
+ ( label.fontsize = penguinct 10 ,
+ ) label.family = +
- "ibm"
+ )
+
+
+
+
+
+
+
+
+
+And other geom_mark_*
like hull, circle, ellpse, rect.
+
+
+Code
+p2 geom_edge +
+ ( color geom_mark_ellipse (
+ = aes ("gray80" fill = species, ) label = species),
+ +
- alpha = geom_edge_label 0.1 ,
+ ( color color = = "transparent" , "gray50" , size # a nice touch sometimes! (imho)
+ = label.colour = 4 "gray30" ,
+ ) label.family = +
- "ibm" ,
+ geom_node_label label.fontsize = (
- 8 ,
+ aes # label.fontface = "plain",
+ ( label # this is just for blogpost
+ = expand = splitvar unit () ,
- color - = 5 , "gray30" ,
- label.col "mm" ),
+ = radius = NA , unit (# no box
- size 5 , = "mm" )
+ ) 4 ,
- label.padding +
+ = geom_mark_circle (
+ unit aes (
+ ( filter = 0.5 , coalesce (bill_length_mm, "lines" 0 ) ) ,
- ids == = max (bill_length_mm, "inner"
- na.rm = ) TRUE ),
+ +
- label = geom_node_plot NULL ,
+ (
- gglist description = = "A rare penguin!"
+ ),
+ list color = (
- "gray70" ,
+ geom_point fill = (
- "transparent" ,
+ aes label.fontsize = ( x 8 ,
+ = label.family = bill_length_mm , y "ibm"
+ ) = +
+ bill_depth_mm , color theme (= legend.position = species "none" ) ) ,
- size +
+ = labs (1 , alpha x = = NULL , 0.5
- y = ) ,
- NULL )
+
+
+
+
+
+
+
+
+
+Now imagine we used a -means algorithm:
+
+
+Code
+dcenters scale_color_viridis_d <- penguins ( end |>
+ = select (species, bill_length_mm, bill_depth_mm) 0.9 |>
+ ) ,
- filter (guides ! ( color is.na (bill_length_mm)) = |>
+ guide_legend filter (( override.aes ! = is.na (bill_depth_mm)) list |>
+ ( size group_by (species) = |>
+ 5 summarise () across () everything (), median)) ) ,
- |>
+ theme_minimal select (( - species) ) ,
- |>
+ theme mutate (( axis.text cluster = = as.character (element_text row_number ()))
+
+dcenters
+
+
+
# A tibble: 3 × 3
+ bill_length_mm bill_depth_mm cluster
+ <dbl> <dbl> <chr>
+1 38.8 18.4 1
+2 49.6 18.4 2
+3 47.4 15 3
+
+
+Code
+bnd ( size <- penguins = |>
+ 7 summarise (
+ ) min (bill_length_mm, ) ,
- na.rm = labs TRUE ) ( x - = 1 ,
+ NULL , y max (bill_length_mm, = na.rm = NULL TRUE ) )
- + ) ,
- scales 1 ,
+ = min (bill_depth_mm, "fixed" ,
- id na.rm = = TRUE ) "terminal"
- - ) 1 ,
+ +
- max (bill_depth_mm, geom_node_label na.rm = (
- TRUE ) aes + ( label 1
+ ) = |>
+ sprintf as.list () ( |>
+ "Node %s (n = %s)" , unlist () id , |>
+ nodesize as.vector ()
+
+p2 ) +
+ ) ,
- ids geom_voronoi_tile (
+ = aes ("terminal" ,
- size fill = cluster, = group = 3 ,
- label.col - = 1 ),
+ NA , data = dcenters, # no box
- nudge_y alpha = = 0.2 , 0.01
- bound = bnd
+ ) )
-
-
-{parttree}
-Source: https://github.com/grantmcdermott/parttree .
-I use the {parttree} package when the model is simple, or when I want to explain the decision tree algorithm.
-
-
Code +
+ # remotes::install_github("grantmcdermott/parttree")
-geom_voronoi_segment (
+ library aes (( group = parttree - )
-
-1 ),
+ # 2 independent variables
-data = dcenters, penguinct2 color = <- "gray90" , ctree bound = bnd
+ ) (
- +
+ species xlim (bnd[~ 1 ], bnd[bill_length_mm 2 ]) + +
+ bill_depth_mm ,
- data ylim (bnd[= 3 ], bnd[penguins ,
- control 4 ]) = +
+ ctree_control scale_fill_viridis_d (( maxdepth direction = = - 3 1 , )
- option = )
-
-"C" ) ggplot +
+ ( # its better put point over all layers
+ penguins , geom_point (
+ aes aes (( x color = species),
+ = size = bill_length_mm , y 2 ,
+ = shape = bill_depth_mm 21 ,
+ ) color = ) "gray90"
+ ) +
- geom_parttree theme ((
- data legend.position = = "right" )
+
+
+
+
+
+
+
+
+
+
+
+{ggfittext}
+Source: https://github.com/wilkox/ggfittext .
+This package have a lot of features to work with strings in ggplot objects, particulary when you use treemaps.
+A love the simple and useful function geom_bar_text()
+ geom_col()
combo.
+
+Code
+penguinct2 ,
- library (ggfittext)
+
+p3 aes <- penguins ( fill |>
+ = count (species) species |>
+ ) ,
- alpha mutate (= n = 0.2 ,
- color 100 = * n) "gray60" ,
- |>
+ ) ggplot (+
- aes (species, n)) geom_point +
+ ( geom_col (aes width = ( col 0.35 , = fill = species "cyan4" )
+
+p3 ) +
+ ) geom_bar_text ()
+p3 +
- theme_minimal ( geom_bar_text (
+ )
-
-
-
-
-
-{ggparty}
+ {parttree}
-
-
-
Code formatter = scalesdpred_node :: <- comma_format (),
+ penguins padding.y = grid|>
- :: select unit (( 2.5 , species , "mm" )
+ )
+p3 bill_length_mm , +
+ bill_depth_mm geom_bar_text (
+ ) formatter = scales|>
- :: mutate comma_format (),
+ (
- id place = = "bottom" ,
+ predict padding.y = grid( :: penguinct2 , type unit (= 2.5 , "node" , newdata "mm" )
+ )
+
+
+
+
+{scales}
+Source: https://scales.r-lib.org/ .
+You use this package using a label_*
function in the labels
argument of scale_*
function.
+
+
+Code
+= library (scales) penguins # comma dollar label_comma
+
+x ) ,
- species_pred <- = c (predict 123 , ( 456678 , penguinct2 , newdata 100000 )
+
+= c (penguins comma (x), )
- dollar (x))
+
+
+
[1] "123" "456,678" "100,000" "$123" "$456,678" "$100,000"
+
+
+Code
+) # I know the correct alternative is Mpg
+miles_per_gallon |>
- <- group_by label_comma (( suffix = id " mi/gal" )
+
+wt_lbl ) <- |>
- label_comma (summarise scale = (
- species 1000 , = suffix = unique " lbs" )
+
+p1 ( +
+ species_pred scale_y_continuous (
+ ) ,
- bill_length_mm labels = miles_per_gallon,
+ = name = mean "fuel consumption"
+ ) ( +
+ bill_length_mm scale_x_continuous (
+ ) ,
- bill_depth_mm labels = wt_lbl,
+ = name = mean "weigth"
+ )
+
+
+
+
+
+
+
+
+
+
+
+{ggparty}
+Source: https://github.com/martin-borkovec/ggparty .
+
+
+Code
+( library (partykit) bill_depth_mm # ctree
+)
- library (ggparty)
+
+penguinct )
-
-<- dpred_node
-
-
# A tibble: 5 × 4
- id species bill_length_mm bill_depth_mm
- <int> <fct> <dbl> <dbl>
-1 3 Adelie 37.4 15.2
-2 4 Adelie 38.5 18.4
-3 6 Gentoo 47.4 14.9
-4 8 Adelie 43.0 18.2
-5 9 Chinstrap 49.5 18.4
-
-
Code ctree (
+ species dparttree ~ bill_length_mm <- + bill_depth_mm parttree + flipper_length_mm ( + body_mass_g penguinct2 + sex,
+ )
-data = penguins
+ )
+
+dparttree autoplot (penguinct)
+
+
+
+
+
+
+
+
+
+
+
+Code
+<- ggparty (penguinct) dparttree +
+ |>
- geom_edge (as_tibble color = ( "gray80" ) ) +
+ |>
- geom_edge_label (rename color = ( id "gray50" , = size = node 4 ) ) +
+ |>
- geom_node_label (
+ select aes (( label = splitvar),
+ - color = path "gray30" ,
+ )
-
-label.col = ggp NA , <- # no box
+ ggparty size = ( 4 ,
+ penguinct2 label.padding = )
-
-unit (ggp 0.5 , $ "lines" ),
+ data ids = <- "inner"
+ ) ggp +
+ $ geom_node_plot (
+ data gglist = |>
- list (
+ as_tibble geom_point (
+ ( aes () x = bill_length_mm, |>
- y = bill_depth_mm, left_join color = species),
+ (
- size = dpred_node 1 , |> alpha = select 0.5
+ ),
+ ( scale_color_viridis_d (id , end = species 0.9 ),
+ ) ,
- by guides (= color = join_by guide_legend (( override.aes = id list ()
- size = )
-
-5 ))),
+ ggp theme_minimal (),
+ +
- theme (geom_edge axis.text = ( color element_text (= size = "gray80" 7 )),
+ ) labs (+
- x = geom_edge_label NULL , ( color y = = NULL )
+ ),
+ "gray50" , size scales = = "fixed" ,
+ 4 id = ) "terminal"
+ ) +
- geom_node_label geom_node_label (
+ (
- aes (aes label = ( label sprintf (= "Node %s (n = %s)" , id, nodesize)),
+ str_replace_all ids = ( "terminal" ,
+ splitvar , size = "_" , 3 ,
+ " " label.col = ) NA , ) ,
- color # no box
+ = nudge_y = "gray30" ,
- label.col 0.01
+ )
+
+
+
+
+
+
+
+
+
+
+
+{parttree}
+Source: https://github.com/grantmcdermott/parttree .
+I use the {parttree} package when the model is simple, or when I want to explain the decision tree algorithm.
+
+
+Code
+= # remotes::install_github("grantmcdermott/parttree")
+NA , library (parttree)
+
+# no box
- size # 2 independent variables
+penguinct2 = <- 4 ,
- label.padding ctree (
+ species = ~ bill_length_mm unit + bill_depth_mm,
+ ( data = penguins,
+ 0.5 , control = "lines" ctree_control () ,
- ids maxdepth = = 3 )
+ )
+
+"inner"
- ggplot (penguins, ) aes (x = bill_length_mm, y = bill_depth_mm)) +
- geom_node_plot geom_parttree (
+ (
- gglist data = penguinct2,
+ = aes (list fill = species),
+ (
- alpha = geom_point 0.2 ,
+ (
- color = aes "gray60" ,
+ ) ( x +
+ = geom_point (bill_length_mm , y aes (= col = species)) bill_depth_mm , color +
+ = theme_minimal ()
+
+
+
+
+
+
+
+
+
+
+
+{ggparty}
+ {parttree}
+
+
+Code
+dpred_node species <- penguins ) ,
- size |>
+ = select (species, bill_length_mm, bill_depth_mm) 1 , alpha |>
+ = mutate (
+ 0.5
- id = ) ,
- predict (penguinct2, type = geom_parttree "node" , (
- data newdata = penguins),
+ = species_pred = penguinct2 ,
- predict (penguinct2, aes newdata = penguins)
+ ) ( fill |>
+ = group_by (id) species |>
+ ) ,
- alpha summarise (
+ = species = 0.1 ,
- color unique (species_pred),
+ = bill_length_mm = "gray60" ,
- mean (bill_length_mm),
+ ) ,
-
- bill_depth_mm = geom_point mean (bill_depth_mm)
+ )
+
+dpred_node
+
+
+
# A tibble: 5 × 4
+ id species bill_length_mm bill_depth_mm
+ <int> <fct> <dbl> <dbl>
+1 3 Adelie 37.4 15.2
+2 4 Adelie 38.5 18.4
+3 6 Gentoo 47.4 14.9
+4 8 Adelie 43.0 18.2
+5 9 Chinstrap 49.5 18.4
+
+
+Code
+dparttree (
- data <- = parttree (penguinct2)
+dparttree dpred_node ,
- <- dparttree aes |>
+ ( x as_tibble () = |>
+ bill_length_mm , y rename (= id = node) bill_depth_mm , color |>
+ = select (species - path)
+
+ggp ) ,
- size <- = ggparty (penguinct2)
+
+ggp3
- $ data ) ,
-
- <- ggpgeom_rect $ data (
- data |>
+ = as_tibble () dparttree ,
- |>
+ aes left_join (
+ dpred_node ( xmin |> = select (id, species),
+ xmin , xmax by = = join_by (id)
+ )
+
+ggp xmax , ymin +
+ = geom_edge (ymin , ymax color = = "gray80" ) ymax , fill +
+ = geom_edge_label (species color = ) ,
- alpha "gray50" , = size = 0.5 ,
- color 4 ) = +
+ "gray40" ,
- geom_node_label (
+ ) ,
-
- aes (scale_fill_manual label = ( values str_replace_all (splitvar, = "_" , colors " " )),
+ ) ,
- color = scale_color_manual "gray30" ,
+ ( values label.col = = NA , colors # no box
+ ) ,
- size = # scale_color_viridis_d(end = 0.9),
- 4 ,
+ # scale_fill_viridis_d(end = 0.9),
- label.padding = guides unit (( color 0.5 , = "lines" ),
+ guide_legend ids = ( override.aes "inner"
+ ) = +
+ list geom_node_plot (
+ ( sizegglist = = list (
+ 5 geom_point (
+ ) aes () x = bill_length_mm, ) ,
- y = bill_depth_mm, theme_minimal color = species),
+ ( size = ) ,
- 1 , theme alpha = ( axis.text 0.5
+ ),
+ = geom_parttree (
+ element_text data = penguinct2,
+ ( size aes (= fill = species),
+ 7 alpha = ) 0.1 ,
+ ) ,
- color = labs "gray60" ,
+ ),
+
+ ( x geom_point (
+ = data = dpred_node,
+ NULL , y aes (= x = bill_length_mm, NULL y = bill_depth_mm, )
- color = species),
+ ) ,
- scales size = = 3
+ ),
+
+ "fixed" ,
- geom_rect (
+ # id = "all"
- id data = dparttree,
+ = aes ("terminal"
- xmin = xmin, ) xmax = xmax, +
- ymin = ymin, geom_node_label ymax = ymax, (
- fill = species),
+ aes alpha = ( label 0.5 ,
+ = color = str_glue "gray40" ,
+ ),
+
+ ( scale_fill_manual ("{species} (#{id}, n = {nodesize})" values = colors),
+ ) scale_color_manual () ,
- ids values = colors),
+ = # scale_color_viridis_d(end = 0.9),
+ "terminal" ,
- size # scale_fill_viridis_d(end = 0.9),
+ = guides (3 ,
- family color = = guide_legend ("ibm" ,
- label.col override.aes = = list (NA , size= # no box
- nudge_y 5 ))),
+ = theme_minimal (),
+ 0.01
- theme ()
-
-
- {patchwork}
-Source: https://patchwork.data-imaginist.com/articles/patchwork.html .
-
-
Code axis.text = library element_text (( size = patchwork 7 )),
+ )
-
-labs (p2 x = <- NULL , p2 y = +
- NULL )
+ ),
+ scale_color_manual scales = ( values "fixed" ,
+ = # id = "all"
+ colors id = ) "terminal"
+ ) +
- theme ( legend.position geom_node_label (
+ = aes ("none" label = )
-
-str_glue (p3 "{species} (#{id}, n = {nodesize})" )),
+ <- ids = p3 "terminal" ,
+ +
- size = geom_col 3 ,
+ ( family = aes "ibm" ,
+ ( fill label.col = = NA , species # no box
+ ) , width nudge_y = = 0.01
+ )
+
+
+
+
+
+
+
+
+
+
+
+{patchwork}
+Source: https://patchwork.data-imaginist.com/articles/patchwork.html .
+
+
+Code
+0.5 library (patchwork)
+
+p2 ) <- p2 +
- scale_fill_manual scale_color_manual (( values values = colors) = +
+ colors , name theme (= legend.position = NULL "none" )
+
+p3 )
-
-<- p3 pp +
+ <- geom_col (( aes (( fill = species), p1 width = / 0.5 ) p3 +
+ ) scale_fill_manual (| values = colors, p2 name = ) NULL )
+
+pp +
- <- ((p1 plot_layout / p3) (
- widths | p2) = +
+ c plot_layout (
+ ( widths = 1 , c (2 1 , ) ,
- guides 2 ),
+ = guides = "collect"
- ) ) +
- plot_annotation plot_annotation (
+ (
- title = title = "Some ggplot2 objects" ,
- subtitle = subtitle = "The plot (a) shows one aspect, while (b) presents additional data." ,
- tag_levels = tag_levels = "a" ,
- tag_prefix = tag_prefix = "(" ,
- tag_suffix = tag_suffix = ")"
- )
-
-pp
-
-
+
+
+
+
+
-
Citation BibTeX citation:
@online{kunstfuentes2023,
- author = {Joshua Kunst Fuentes},
+
+
+Citation BibTeX citation:
@online{kunst fuentes2023,
+ author = {Kunst Fuentes, Joshua},
title = {My Favorite `Ggplot2` Packages with Examples},
date = {2023-07-23},
url = {https://jkunst.com/blog/posts/2023-07-10-my-favorite-ggplot2-packages-with-examples},
langid = {en}
}
-
For attribution, please cite this work as:
-Joshua Kunst Fuentes. 2023.
“My Favorite `Ggplot2` Packages with
+For attribution, please cite this work as:
+Kunst Fuentes, Joshua. 2023.
“My Favorite `Ggplot2` Packages with
Examples.” July 23, 2023.
https://jkunst.com/blog/posts/2023-07-10-my-favorite-ggplot2-packages-with-examples .
]]>
minipost
diff --git a/docs/posts/2000-01-01-quarto-post-example/index.html b/docs/posts/2000-01-01-quarto-post-example/index.html
index 5c73dad..344790f 100644
--- a/docs/posts/2000-01-01-quarto-post-example/index.html
+++ b/docs/posts/2000-01-01-quarto-post-example/index.html
@@ -316,8 +316,8 @@ Testing htmlwidgets```
@@ -467,8 +467,8 @@
Marging content
diff --git a/docs/posts/2023-07-10-my-favorite-ggplot2-packages-with-examples/index.html b/docs/posts/2023-07-10-my-favorite-ggplot2-packages-with-examples/index.html
index 7292545..cec7597 100644
--- a/docs/posts/2023-07-10-my-favorite-ggplot2-packages-with-examples/index.html
+++ b/docs/posts/2023-07-10-my-favorite-ggplot2-packages-with-examples/index.html
@@ -1,11 +1,14 @@
-
+
-
+
+
+
+
Data, Code and Visualization - My favorite ggplot2 packages with examples
+
@@ -99,13 +74,20 @@
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
+
+
+
-