在 R 中使用 GGPlot 时如何抑制等值线图中的颜色条

问题描述 投票:0回答:1

我正在尝试使用

ggplot
中的
r
库制作一组等高线图来显示密度函数。这些等高线图都将被标准化,因此 GGPlot 默认生成的颜色条是不必要的,并且会使图像变得混乱。我正在寻找一种方法来抑制这些颜色条。

这是一个基本的工作示例:

#Some randomly generated data, using xnorm <- rnorm(100, 100, 2) and ynorm <- rnorm(100, 100, 1)  
xnorm <- c(100.63747,  99.61373, 102.78140,  97.55596,  99.73000,  97.48554, 101.09937, 102.27442,  98.44345,  98.63937, 95.18071, 100.99034, 100.25796,  99.85286, 101.37154, 103.62904,  98.52518,  99.29083, 98.43506, 100.04028, 100.50882, 101.83978,  97.61325,  99.25491,  97.67031, 100.76768, 101.15345,  99.45239,  99.00706,  99.25894, 101.67204,  98.53558, 103.28598,  99.37674,  98.29560, 102.57874, 101.78405,  96.64773,  98.57429, 102.58449, 102.34099, 101.76433,  99.42075,  96.68118,  98.21205,  98.60703, 103.40764, 100.38115, 101.02439,  96.77698,  96.95160,  98.77218, 100.74975,  96.60388, 100.82192, 100.31073,  98.66408,  96.43205, 101.66969,  99.22321, 100.76002,  96.41930,  99.01634,  96.66087, 100.78227,  95.19014,  98.61710,  98.12931, 101.02011,  99.38666, 104.99480, 100.88542, 100.12007,  97.54670,  98.56362,  98.38221,  98.01062,  99.57980,  99.79977, 101.61598,  99.70361,  98.49786,  97.03384,  98.88931,  96.49175, 101.65014,  98.50976, 102.70204, 103.10644, 100.1625, 101.50492 , 96.78505,  97.64607,  96.23355, 100.83890, 103.89213,  96.55422,  98.14217,  97.33865, 103.09313) 
ynorm <- c(101.00065,  99.01183, 101.03233,  99.87815, 101.42570,  98.62362,  98.75669,  99.11513,  98.08216,  99.93417,  99.55935,  98.59495, 100.56597,  99.82176, 100.28809, 101.41834, 101.15464, 100.27552, 98.47943,  99.26038, 100.03685, 101.29748, 100.78959, 98.89097, 101.30694, 100.49280,  98.63089, 100.79754, 100.14726, 101.13723,  99.52545,  98.15186,  98.04923, 100.32256,  99.40237,  99.29262, 100.35762,  98.66520, 100.22026,  99.13309,  98.59964, 101.88812,  99.92022, 100.63701, 100.05824, 100.99503,  98.82681,  99.17443, 100.80232,  99.28913, 100.57291, 100.37855,  99.84050,  98.30520, 99.69184,  98.44987,  99.44457,  99.44025,  98.90528,  98.95814,  99.95515,  99.79427,  99.53203,  99.08064, 100.30757,  98.70576,  96.13955, 100.01945, 100.54303, 101.35302,  99.91294,  98.85087, 101.03512, 100.74202,  99.40307, 100.08632, 100.26612, 101.96658,  98.12320,  99.77385,  99.97723, 100.41529,  99.99487,  99.56625,  97.87832, 101.47635, 101.01801,  99.67586,  99.17761, 100.50633, 99.61379, 101.79323, 100.37171, 100.58981,  99.44867, 100.62373,  99.69169, 100.65622,  99.91878,  99.65549) 

cplot <- ggplot(mapping = aes(x = xnorm, y = ynorm)) + 
geom_density_2d_filled(aes(fill = after_stat(level)), breaks = seq(0.1, 1, length.out = 10), contour_var = 'ndensity') + 
geom_density_2d(contour_var = 'ndensity')
print(cplot)

此代码产生以下图: Contour plot generated with GGPlot.  I would like to get rid of the colorbar 该等高线图看起来或多或少符合我的要求,但我想删除显示标准化级别的颜色条。有什么简单的方法可以做到这一点吗?浏览

ggplot
的文档并没有得到任何我理解的内容。

感谢您的帮助!

r plot visualization contourf
1个回答
0
投票
eom_density_2d_filled(aes(fill = after_stat(level)), breaks = seq(0.1, 1, length.out = 10), contour_var = 'ndensity') + 
geom_density_2d(contour_var = 'ndensity')+
  theme(legend.position = "none") # this removes the legend
print(cplot)

© www.soinside.com 2019 - 2024. All rights reserved.