希腊字母为统计密度2d图

时间:2016-01-13 12:41:15

标签: r ggplot2

考虑以下情节:

# fake data
set.seed(1234)
n <- 200
gg <- data.frame(wf=rnorm(n,0.5),wb=rnorm(n,0.5),z=runif(n,0,6))

# plot it
gg$`My Title` <- gg$z
ggplot(data=gg, aes(x=wf, y=wb, color=`My Title`)) + 
  geom_point(aes(colour=z),shape="") +
  stat_density2d(aes(fill = ..level..),n = 100,contour = TRUE,geom = "polygon") +
  labs(x=expression(w[f]),y=expression(w[b])) +
  guides(fill=F)

enter image description here

我想将My Title更改为希腊字母或希腊字母的混合文字。 谢谢!

1 个答案:

答案 0 :(得分:6)

添加guides(colour=guide_colorbar(title=expression(paste("This is a greek letter: ", alpha))))应该有效:

# fake data
set.seed(1234)
n <- 200
gg <- data.frame(wf=rnorm(n,0.5),wb=rnorm(n,0.5),z=runif(n,0,6))

ggplot(data=gg, aes(x=wf, y=wb, color=z)) + 
 geom_point(aes(colour=z),shape="") +
 stat_density2d(aes(fill = ..level..),n = 100,contour = TRUE,geom = "polygon") +
 labs(x=expression(w[f]),y=expression(w[b])) + guides(fill=F) +     
 guides(colour=guide_colorbar(title=expression(paste("This is a greek letter: ", alpha))))

enter image description here