r - What's the meaning of ".." in R
问题描述
When plotting a contour plot, "..level.." is used in the code.
ggplot(faithful, aes(eruptions, waiting)) + stat_density2d(aes(colour = ..level..))
When plotting a barplot, "..count.." is used.
x <- sample(c('A','B','C','D'), size = 1000, replace= TRUE, prob = c(0.2,0.3,0.3,0.2))
y <- rnorm(1000) * 1000
df = data.frame(x= x, y = y)
ggplot(data = df, aes(x = factor(x), y = ..count..))+ geom_bar(stat = 'count')
If we replace "..count.." with "count", an error occurs. So what is the difference?
解决方案
..count..
是一个标识符,就像 R 中的任何其他标识符一样,因为.
它只是一个可以在 R 中的标识符中使用的普通字符——不像在其他编程语言中,它通常是一个特殊的运算符。请记住,在 R 中,您可以定义一个名为 的变量data.set
:
data.set <- data.frame(a=1:3, b=4:6)
变量名中的句点只是一个普通的标识符字符,如字母。
碰巧这..count..
是一个标识符,它被选择ggplot
来表示其特征之一,即基于计数的密度估计。
推荐阅读
- javascript - Express Session Not updating from route files
- javascript - List of features introduces in each Javascript version
- dart - how to override the toString method of an enum in dart
- c++ - CUDA 断言 - __host__ __device__ 上的过载,为什么没有警告/错误?
- react-native - 我如何禁用两个滚动视图内的内容滚动
- python - Extracting coordinates from a list (polygon) created after running the program. Python
- javascript - Test case for multimedia upload is not working
- django - query a datetime field with just date in django
- mysql - Deprecated display width for integer data types
- flutter - Setstate is not working in my calculator app in flutter