有没有办法在ggplot中定义自己的线型? 在线图中,我希望线条显示为小数字。有点像线型“点缀”只是用小“1”或“2”代替点。 我用标签试了一下,但它们只在定义的点上显示,而不是在两者之间的空格中显示。我无法弄明白,如何将其实现到scale_linetype_manual
if (!defined('ROLE_ADMIN')) {
define('ROLE_ADMIN', 'admin');
}
if (!defined('ROLE_MASTER')) {
define('ROLE_MASTER', 'master');
}
if (!defined('ROLE_REGULAR')) {
define('ROLE_REGULAR', 'regular');
}
if (!defined('EDITION_ALL,')) {
define('EDITION_ALL,', ['CXEE1502-de','CXPE1502-de','CXTE1502-de','CXBE1502-de']);
}
return [
'acl' => [
'index' => [
'index' => [
'roles' => [ROLE_ADMIN, ROLE_MASTER, ROLE_REGULAR],
'products' => EDITION_ALL,
]
],
'dashboards' => [
'dashboard' => [
'roles' => [ROLE_ADMIN, ROLE_MASTER, ROLE_REGULAR],
'products' => EDITION_ALL,
]
],
]
]
答案 0 :(得分:1)
您可以尝试调整this strategy将路径拆分为等间距段
set.seed(123)
df <- data.frame(
x = runif(10),
y = runif(10),
z = c(1,1,1,1,1,2,2,2,2,2))
parametric_smoothie <- function(x, y, sort = TRUE, N=1e2, phase=1, offset=0) {
if(sort){
ox <- order(x)
x <- x[ox]
y <- y[ox]
}
lengths <- c(0, sqrt(diff(x)^2 + diff(y)^2))
l <- cumsum(lengths)
lmax <- max(l)
newpos <- seq(phase*lmax/N, lmax-phase*lmax/N, length.out = N) + offset*lmax/N
xx <- approx(l, x, newpos)$y
yy <- approx(l, y, newpos)$y
## new points, equi-spaced
dnew <- data.frame(x = xx, y = yy)
xx <- c(x, xx)
yy <- c(y, yy)
ox <- order(xx)
xx <- xx[ox]
yy <- yy[ox]
## original and new points combined
dcomb <- data.frame(x = xx, y = yy)
list(dnew = dnew, dcomb = dcomb)
}
dl <- plyr::dlply(df, "z", function(.d) parametric_smoothie(.d$x, .d$y, N=10))
df2 <- plyr::ldply(dl, "[[", "dnew")
df3 <- plyr::ldply(dl, "[[", "dcomb")
ggplot(df, aes(x, y)) +
geom_line(data = df3, aes(colour=as.factor(z))) +
geom_point(data = df2, colour = "grey92", size=5) +
geom_point(aes(colour=as.factor(z))) +
geom_text(data = df2, aes(label=z), size=3)