gpt4 book ai didi

r - 带有数据标签的stat_contour

转载 作者:行者123 更新时间:2023-12-03 13:28:27 24 4
gpt4 key购买 nike

我想知道如何在ggplot2中的轮廓线上获取数据标签。谢谢

require(grDevices) # for colours

x <- seq(-4*pi, 4*pi, len = 27)
y <- seq(-4*pi, 4*pi, len = 27)
r <- sqrt(outer(x^2, y^2, "+"))

rx <- range(x <- 10*1:nrow(volcano))
ry <- range(y <- 10*1:ncol(volcano))
ry <- ry + c(-1, 1) * (diff(rx) - diff(ry))/2

plot(
x = 0
, y = 0
, type = "n"
, xlim = rx
, ylim = ry
, xlab = ""
, ylab = ""
)

contour(
x = x
, y = y
, z = volcano
, add = TRUE
)

library(ggplot2)
library(reshape2)
volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")

# Basic plot
v <- ggplot(volcano3d, aes(x, y, z = z))
v + stat_contour()

最佳答案

使用directlabels程序包并从this中选择解决方案

# Basic plot
v <- ggplot(volcano3d, aes(x, y, z = z))
library(directlabels)
v2 <- v + stat_contour(aes(colour = ..level..))
direct.label(v2, method="bottom.pieces")

关于r - 带有数据标签的stat_contour,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13627735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com