..level.. in ggplot2 contour plot

☆樱花仙子☆ 提交于 2019-12-21 07:54:56

问题


I find this variable a little confusing, for example, from the docs:

require(ggplot2)
require(reshape2)
volcano3d <- melt(volcano) 
names(volcano3d) <- c("x", "y", "z") 
v <- ggplot(volcano3d, aes(x, y, z = z)) 
v1 = v +  stat_contour(aes(colour=..level..,size=..level..)) 

Why can't I use this:

v2 = v +  stat_contour(aes(colour=as.factor(z),size=as.factor(z))) 

回答1:


From Hadley Wickham's A Layered Grammar of Graphics, page 21, the .. .. is used because the aesthetic (in this case, the levels of the contours) is not present in the original dataset, but instead is calculated by the contour statistic.

The two dots are a visual indicator highlighting that variable is not present in the original data, but has been computed by the statistic.

You can't use colour=as.factor(z) or size=as.factor(z) because the graphic doesn't use z, but instead uses a statistical transformation of it - namely, ..level..



来源:https://stackoverflow.com/questions/19688649/level-in-ggplot2-contour-plot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!