my previous question ürününde oluşturduğum bu grafiğe daha fazla ek açıklama eklemek istiyorum. ggplot annotation_grob'a nokta ve metin ekleyin?
set.seed(40816)
library(ggplot2)
library(grid)
df.plot <- data.frame(x = rnorm(100, 0, 1))
strainerGrob <- function(pos=unit(4,"mm"), gp=gpar(lty=2, lwd=2))
segmentsGrob(0, unit(1,"npc") - pos, 1, unit(1,"npc") - pos, gp=gp)
ggplot(df.plot, aes(x = x)) + geom_density() +
annotation_custom(strainerGrob(), xmin = -1, xmax = 1, ymin=-Inf, ymax=0)
ben nokta üzerinde 0
ve 0 segmentinde sağ, bir noktaya 1
soluna -1
eklemek istiyorum
y
için mutlak mesafe kullanmak zorunda kalmadan. Mümkün mü? Şu anda sert
y
ggplot(df.plot, aes(x = x)) + geom_density() +
annotation_custom(strainerGrob(), xmin = -1, xmax = 1, ymin=-Inf, ymax=0) +
geom_point(aes(x=0, y=-0.01)) +
annotate("text", x = -1, y = -0.01, label = -1, hjust = 1.5) +
annotate("text", x = 1, y = -0.01, label = 1, hjust = -1) +
annotate("text", x = 0, y = 0, label = 0, vjust = 2.75)
kodlama yapabilir Ama verileri değiştirmek durumunda noktası ve diğer açıklamaları yanlış yerde sonunda.
df.plot <- data.frame(x = rnorm(100, 0, 4))
ggplot(df.plot, aes(x = x)) + geom_density() +
annotation_custom(strainerGrob(), xmin = -1, xmax = 1, ymin=-Inf, ymax=0) +
geom_point(aes(x=0, y=-0.01)) +
annotate("text", x = -1, y = -0.01, label = -1, hjust = 1.5) +
annotate("text", x = 1, y = -0.01, label = 1, hjust = -1) +
annotate("text", x = 0, y = 0, label = 0, vjust = 2.75)
Çok teşekkür ederim! Bu harika! – Ignacio
'xmax' i 'xmax = 2' 'i değiştirdiğimde nokta ve' 0' hareket eder. Bana onları x = 0'da nasıl tutacağını gösterebilir misin? – Ignacio
Sorunuzda ne yapmaya çalıştığınızı açıklayabilir misiniz? Soruyu sabit değerlerle cevapladım, ama asıl sorunundaki değişkenin ne olabileceği hakkında hiçbir fikrim yok. Veri koordinatlarını ve diğer ızgara ünitelerini karıştırmak genelde biraz zor olabilir. – baptiste