gpt4 book ai didi

r - 填充 geom_curve ggplot2 上的箭头

转载 作者:行者123 更新时间:2023-12-03 23:27:59 26 4
gpt4 key购买 nike

有没有办法让geom_curve上的箭头关闭?相同的代码适用于 geom_segment。也许它是一个错误?

library(tidyverse)

set.seed(123)

data <- data_frame(x = rnorm(10), y = rnorm(10))

# NO ARROWHEAD FILL

ggplot(data, aes(x, y)) +
geom_point() +
geom_curve(aes(x = 0, y = 0, xend = 1, yend = 1),
color = "black",
arrow = arrow(type = "closed"))

# ARROWHEAD FILL WORKS

ggplot(data, aes(x, y)) +
geom_point() +
geom_segment(aes(x = 0, y = 0, xend = 1, yend = 1),
color = "black",
arrow = arrow(type = "closed"))

最佳答案

我称之为错误,你应该提交一个问题。直到那时:

geom_curve2 <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
...,
curvature = 0.5,
angle = 90,
ncp = 5,
arrow = NULL,
lineend = "butt",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
stat = stat,
geom = GeomCurve2,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
arrow = arrow,
curvature = curvature,
angle = angle,
ncp = ncp,
lineend = lineend,
na.rm = na.rm,
...
)
)
}

GeomCurve2 <- ggproto("GeomCurve2", GeomSegment,
draw_panel = function(data, panel_params, coord, curvature = 0.5, angle = 90,
ncp = 5, arrow = NULL, lineend = "butt", na.rm = FALSE) {
if (!coord$is_linear()) {
warning("geom_curve is not implemented for non-linear coordinates",
call. = FALSE)
}
trans <- coord$transform(data, panel_params)

curveGrob(
trans$x, trans$y, trans$xend, trans$yend,
default.units = "native",
curvature = curvature, angle = angle, ncp = ncp,
square = FALSE, squareShape = 1, inflect = FALSE, open = TRUE,
gp = gpar(
col = alpha(trans$colour, trans$alpha),
fill = alpha(trans$colour, trans$alpha),
lwd = trans$size * .pt,
lty = trans$linetype,
lineend = lineend),
arrow = arrow
)
}
)

这导致:
ggplot(data, aes(x, y)) + 
geom_point() +
geom_curve2(aes(x = 0, y = 0, xend = 1, yend = 1),
color = "black",
arrow = arrow(type = "closed"))



enter image description here

关于r - 填充 geom_curve ggplot2 上的箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47878787/

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