Usuń "a" z legendy podczas korzystania z estetyki i tekstu geom
Jak mogę usunąć literę " a " z legendy Wygenerowanej Przez ten kod? Jeśli usunę geom_text
, wtedy litera " a " nie pojawi się w legendzie. Chcę jednak zatrzymać geom_text
.
ggplot(data = iris, aes(x = Sepal.Length, y=Sepal.Width, shape = Species, colour = Species)) +
geom_point() +
geom_text(aes(label = Species))
6 answers
Set show.legend = FALSE
in geom_text
:
ggplot(data = iris,
aes(x = Sepal.Length, y = Sepal.Width, colour = Species, shape = Species, label = Species)) +
geom_point() +
geom_text(show.legend = FALSE)
Argument show_guide
zmienił nazwę na show.legend
w ggplot2 2.0.0
(Zobacz release news ).
Pre-ggplot2 2.0.0
:
Z show_guide = FALSE
w ten sposób...
ggplot( data=iris, aes(x=Sepal.Length, y=Sepal.Width , colour = Species , shape = Species, label = Species ) , size=20 ) +
geom_point()+
geom_text( show_guide = F )
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-11 20:54:17
Miałem podobny problem . Rozwiązanie Simona zadziałało dla mnie, ale wymagany był lekki zwrot akcji. Nie zdawałem sobie sprawy, że muszę dodać "show_guide = F" do argumentów geom_text, zamiast zastępować nimi istniejące argumenty - co pokazuje rozwiązanie Simona. Dla takiego nooba ggplot2 jak ja to nie było takie oczywiste. Odpowiedni przykład użyłby kodu OP i po prostu dodał brakujący argument w ten sposób:
..
geom_text(aes(label=Species), show_guide = F) +
..
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:34:40
Jak powiedział Nick
Poniższy kod nadal powodowałby błąd:
geom_text(aes(x=1,y=2,label="",show_guide=F))
}
geom_text(aes(x=1,y=2,label=""),show_guide=F)
Poza argumentem aes eliminuje a nad legendą
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-13 11:34:19
Możemy użyć guide_legend(override.aes = aes(...))
, aby ukryć " a " w legendzie.
Poniżej znajduje się krótki przykład użycia guide_legend()
library(ggrepel)
#> Loading required package: ggplot2
d <- mtcars[c(1:8),]
p <- ggplot(d, aes(wt, mpg)) +
geom_point() +
theme_classic(base_size = 18) +
geom_label_repel(
aes(label = rownames(d), fill = factor(cyl)),
size = 5, color = "white"
)
# Let's see what the default legend looks like.
p
# Now let's override some of the aesthetics:
p + guides(
fill = guide_legend(
title = "Legend Title",
override.aes = aes(label = "")
)
)
Strona korzysta z plików cookies w celu realizacji usług i zgodnie z Polityką Plików Cookies..2.1)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-04-29 19:29:32
Możesz również użyć show.legend = FALSE
w argumentach geom_label_repel()
, aby usunąć " a " w legendzie.
Więc zamiast
ggplot(d, aes(wt, mpg)) +
geom_point() +
theme_classic(base_size = 18) +
geom_label_repel(
aes(label = rownames(d), fill = factor(cyl)),
size = 5, color = "white"
)+ guides(
fill = guide_legend(
title = "Legend Title",
override.aes = aes(label = "")
)
)
Możesz to zrobić,
ggplot(d, aes(wt, mpg)) +
geom_point() +
theme_classic(base_size = 18) +
geom_label_repel(
aes(label = rownames(d), fill = factor(cyl)),
size = 5, color = "white",
show.legend = FALSE )
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-03-17 21:07:43
Miałem podobny problem, z " a " pojawiającym się za różnymi kolorowymi punktami, które starałem się oznaczyć geom_text_repel
. Aby usunąć "a", tak aby po prostu pokazywało punkt bez " a " za nim, musiałem dodać show.legend=FALSE
jako argument w geom_text_repel
.
Mam nadzieję, że to ma sens dla każdego, kto może pracować z tym samym problemem!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-05-23 16:39:32