我有一個看起來像這樣的情節:
library('ggplot2')
df = data.frame(Sepal.Width = 5.6, Sepal.Length = 3.9)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, col = Species))
geom_point()
geom_point(data = df, col = 'blue')
我想在圖例中標記藍色點。我怎么做?
uj5u.com熱心網友回復:
一種方法是為該點指定一種帶有某些名稱的顏色aes。然后,您可以在scale_color_manual.
library(tidyverse)
ggplot(iris, aes(x = Sepal.Width, y = Sepal.Length, col = Species))
geom_point()
geom_point(aes(x = Sepal.Width, y = Sepal.Length, colour = 'Sepal.Width'),
data = df)
scale_color_manual(
values = c(
"Sepal.Width" = "blue",
"setosa" = "red",
"versicolor" = "darkgreen",
"virginica" = "orange"
),
labels = c('New Point', "setosa", "versicolor", "virginica")
)
輸出

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/397021.html
下一篇:R-識別包含任何值集的列
