Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

r - Is there a table or catalog of aesthetics for ggplot2?

I am new to ggplot2 and have been trying to find a comprehensive list of aesthetics. I think I understand their purpose but it is hard to know which can be used in various situations (mostly geoms?). Hadley's website occasionally lists available aesthetics on pages for individual geoms and the R doc's occasionally (though more rarely) do the same. I even found a geom for which the two do not quite match.

I searched through the comments here for an answer and even bought the book! Alas, no help.

I think it would be fantastic to have a table with all the aesthetics listed in one dimension and all the geoms (and other objects?) listed in another.

Does anyone know of such a thing?

Is there a simple way (command) in R to list all the aesthetics that can be applied to an object?

Here's how a table might start:

List           x       y       fill      size    colour   linetype . . .
geom_point    Yes     Yes      Yes       Yes      Yes        No
geom_abline   Yes     Yes      No        Yes      Yes       Yes
.
.
.

A catalog of aesthetic definitions/parameters would be a very helpful reference as well.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Below is the default_aes for each geom,

            colour size linetype alpha   fill weight shape width height angle hjust vjust family fontface lineheight
abline       black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
area           yes  0.5        1   yes grey20     --    --    --     --    --    --    --     --       --         --
bar            yes  0.5        1   yes grey20      1    --    --     --    --    --    --     --       --         --
bin2d          yes  0.5        1   yes grey60      1    --    --     --    --    --    --     --       --         --
boxplot     grey20  0.5    solid   yes  white      1    16    --     --    --    --    --     --       --         --
contour    #3366FF  0.5        1   yes     --      1    --    --     --    --    --    --     --       --         --
crossbar     black  0.5        1   yes    yes     --    --    --     --    --    --    --     --       --         --
density      black  0.5        1   yes    yes      1    --    --     --    --    --    --     --       --         --
density2d  #3366FF  0.5        1   yes     --      1    --    --     --    --    --    --     --       --         --
errorbar     black  0.5        1   yes     --     --    --   0.5     --    --    --    --     --       --         --
errorbarh    black  0.5        1   yes     --     --    --    --    0.5    --    --    --     --       --         --
freqpoly     black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
hex            yes  0.5       --   yes grey50     --    --    --     --    --    --    --     --       --         --
hline        black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
linerange    black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
path         black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
point        black    2       --   yes    yes     --    16    --     --    --    --    --     --       --         --
pointrange   black  0.5        1   yes    yes     --    16    --     --    --    --    --     --       --         --
polygon         NA  0.5        1   yes grey20     --    --    --     --    --    --    --     --       --         --
quantile   #3366FF  0.5        1   yes     --      1    --    --     --    --    --    --     --       --         --
raster          --   --       --   yes grey20     --    --    --     --    --    --    --     --       --         --
rect           yes  0.5        1   yes grey20     --    --    --     --    --    --    --     --       --         --
ribbon         yes  0.5        1   yes grey20     --    --    --     --    --    --    --     --       --         --
rug          black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
segment      black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
smooth     #3366FF  0.5        1   0.4 grey60      1    --    --     --    --    --    --     --       --         --
step         black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --
text         black    5       --   yes     --     --    --    --     --     0   0.5   0.5               1        1.2
tile           yes  0.1        1   yes grey20     --    --    --     --    --    --    --     --       --         --
violin      grey20  0.5    solid   yes  white      1    --    --     --    --    --    --     --       --         --
vline        black  0.5        1   yes     --     --    --    --     --    --    --    --     --       --         --

and the ugly code I used to hack this,

find_aes <- function(geom="point"){

  tryCatch({
  Geom <- getFromNamespace(paste("Geom", ggplot2:::firstUpper(geom), sep=""),
                           "ggplot2")

  tmp <- unclass(Geom$default_aes)
  tmp[is.na(tmp)] <- "yes"
  data.frame(tmp, stringsAsFactors=FALSE)
  }, error = function(e) {})
}

funs <- grep("^geom_", ls("package:ggplot2"),val=T)

geoms <- gsub("^geom_", "", funs)

all <- lapply(geoms, find_aes)
names(all) <- geoms
relevant <- sapply(all, function(x) !is.null(x) && nrow(x) > 0)
library(plyr)
results = do.call("rbind.fill",all)
rownames(results) <- names(relevant[relevant])
results[is.na(results)] <- "--"

options(width=9999)
capture.output(print(results), file="aes.txt")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...