Skip to content

Commit

Permalink
added geom_text and geom_label
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Apr 18, 2024
1 parent 4ea7b23 commit 04c8994
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 6 deletions.
10 changes: 8 additions & 2 deletions R/esquisse-ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ esquisse_ui <- function(id,
list_geoms = c(
list(geomIcons()),
rep_len(list(
geomIcons(c("line", "step", "jitter", "point", "smooth", "density", "boxplot", "violin"), default = "select")
geomIcons(
c("line", "step", "jitter", "point", "smooth", "density", "boxplot", "violin", "text", "label"),
default = "select"
)
), n_geoms)
)
),
Expand Down Expand Up @@ -145,7 +148,10 @@ esquisse_ui <- function(id,
list_geoms = c(
list(geomIcons()),
rep_len(list(
geomIcons(c("line", "step", "jitter", "point", "smooth", "density", "boxplot", "violin"), default = "select")
geomIcons(
c("line", "step", "jitter", "point", "smooth", "density", "boxplot", "violin", "text", "label"),
default = "select"
)
), n_geoms)
)
),
Expand Down
7 changes: 6 additions & 1 deletion R/geometries.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,17 @@ potential_geoms_ref <- function() {
"discrete", "continuous", "point", "0",
"discrete", "continuous", "jitter", "0",
"discrete", "continuous", "violin", "0",
"discrete", "continuous", "text", "0",
"discrete", "continuous", "label", "0",
"continuous", "continuous", "point", "1",
"continuous", "continuous", "jitter", "0",
"continuous", "continuous", "line", "0",
"continuous", "continuous", "step", "0",
"continuous", "continuous", "path", "0",
"continuous", "continuous", "area", "0",
"continuous", "continuous", "smooth", "0",
"continuous", "continuous", "text", "0",
"continuous", "continuous", "label", "0",
"discrete", "discrete", "tile", "1",
"time", "continuous", "line", "1",
"time", "continuous", "point", "0",
Expand Down Expand Up @@ -263,7 +267,8 @@ geomIcons <- function(geoms = NULL, default = c("auto", "blank", "select")) {
"histogram", "density",
"point", "jitter", "smooth",
"boxplot", "violin",
"tile", "sf"
"tile", "sf",
"text", "label"
)
if (is.null(geoms))
geoms <- defaults
Expand Down
3 changes: 2 additions & 1 deletion R/settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ modal_settings <- function(aesthetics = NULL, session = shiny::getDefaultReactiv
tagList(tags$b("shape:"), i18n("shape of the points")),
tagList(tags$b("weight:"), i18n("frequency weights")),
tagList(tags$b("alpha:"), i18n("alpha transparency")),
tagList(tags$b("label:"), i18n("text to use as label on plot")),
tagList(tags$b("group:"), i18n("identifies series of points with a grouping variable")),
tagList(tags$b("ymin:"), tags$span(i18n("used in ribbons charts with ymax to display an interval between two lines"))),
tagList(tags$b("ymax:"), i18n("used in ribbons charts with ymin to display an interval between two lines")),
tagList(tags$b("facet:"), i18n("create small multiples")),
tagList(tags$b("facet row:"), i18n("create small multiples by rows")),
tagList(tags$b("facet col:"), i18n("create small multiples by columns"))
),
choiceValues = c("fill", "color", "size", "shape", "weight", "alpha", "group", "ymin", "ymax", "facet", "facet_row", "facet_col"),
choiceValues = c("fill", "color", "size", "shape", "weight", "alpha", "label", "group", "ymin", "ymax", "facet", "facet_row", "facet_col"),
selected = aesthetics %||% c("fill", "color", "size", "facet"),
status = "primary",
outline = TRUE
Expand Down
Binary file added inst/assets/geomIcon/gg-label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified inst/assets/geomIcon/gg-point.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/assets/geomIcon/gg-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 26 additions & 2 deletions inst/geomIcon/iconGeom.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ ggplot(data = iris) + geom_histogram(mapping = aes(x = Sepal.Length), bins = 20)
png(filename = "inst/geomIcon/www/gg-point.png", bg = "transparent")
ggplot(data = coord_circle(centre = c(0, 0), r = 1)) + geom_polygon(aes(x = x, y = y), fill = "#02C39A") + coord_fixed() + theme_void()
# p <- ggplot(data = mtcars) + geom_point(mapping = aes(wt, mpg), size = 10, color = "white") + theme_void()
p <- ggplot() + geom_point(aes(x = 1:10, y = 1:10), size = 10, color = "white") + theme_void()
print(p, vp = viewport(width = unit(0.6, "npc"), height = unit(0.6, "npc")))
# p <- ggplot() + geom_point(aes(x = 1:10, y = 1:10), size = 10, color = "white") + theme_void()
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point(size = 10, color = "white") + theme_void()
print(p, vp = viewport(width = unit(0.5, "npc"), height = unit(0.5, "npc")))
dev.off()


Expand Down Expand Up @@ -351,3 +352,26 @@ dev.off()



# Geom text ---------------------------------------------------------------

png(filename = "inst/geomIcon/www/gg-text.png", bg = "transparent")
ggplot(data = coord_circle(centre = c(0, 0), r = 1)) + geom_polygon(aes(x = x, y = y), fill = "#CD2EFB") + coord_fixed() + theme_void()
p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
geom_text(color = "white", size = 9) +
theme_void()
print(p, vp = viewport(width = unit(0.8, "npc"), height = unit(0.8, "npc")))
dev.off()



# Geom label --------------------------------------------------------------

png(filename = "inst/geomIcon/www/gg-label.png", bg = "transparent")
ggplot(data = coord_circle(centre = c(0, 0), r = 1)) + geom_polygon(aes(x = x, y = y), fill = "#AC59FB") + coord_fixed() + theme_void()
p <- ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
geom_label(color = "black", size = 9) +
xlim(0, 8) +
ylim(7, 40) +
theme_void()
print(p, vp = viewport(width = unit(0.8, "npc"), height = unit(0.8, "npc")))
dev.off()
Binary file added inst/geomIcon/www/gg-label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified inst/geomIcon/www/gg-point.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inst/geomIcon/www/gg-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04c8994

Please sign in to comment.