【发布时间】:2023-04-07 01:03:01
【问题描述】:
我试图在我的图例中得到一个红点和一个蓝点,这不是我使用的数据,而是一个可重复的示例,
两个数据集的图出口,example是其中之一,example1。
这是我的代码:
if (!require("pacman")) install.packages("pacman")
pacman::p_load_gh("trinker/wakefield")
example <- r_data_frame(
n = 100,
id,
iq,
age,
height
)
example1 <- r_data_frame(
n = 100,
id,
iq,
age,
height)
library(ggplot2)
color_names <- c("example", "example1")
color_values <- c("blue", "red")
names(color_values) <- color_names
ggplot() +
#These points need to be blue and in the legend as well.
geom_point(data=example, aes(x=ID, y=Height,
fill ="example"),
colour="darkblue", size=1) +
#These points need to be red and red in the legend
geom_point(data=example1, aes(x=ID, y=Height,
fill ="example1"), colour = "red"
, size=1) +
# plot configuration scales, theme, etc...
scale_colour_manual(values = color_values) +
scale_fill_manual(values = color_values) +
theme_bw()
【问题讨论】:
标签: r ggplot2 legend scatter-plot