私は階乗グラフを持っており、グラフの各ライン/ポイントで選択した色をコントロールしたいと考えています。私はオンラインリソースを調べて、ggplot2の中で+scale_color_manual()
関数を使うべきであることを見てきました。ggplot2内のポイントのマニュアルカラー
これは、所望の出力を作成しますが、それはまた、私はしたくない余分な凡例を作成します。
余分な凡例を作成せずに回線を介して手動制御を達成するための正しい方法は何ですか、してください?
コード:
# load library
library(ggplot2)
# intialise random seed for reproducibility
set.seed(42)
# generate fictitous averaged data
age <- gl(2, 4, labels = c("Younger", "Older"))
sequence <- gl(2, 2, 8, labels = c("ABA", "CBA"))
response <- gl(2, 1, length = 8, labels = c("Repetition", "Switch"))
accuracy <- runif(length(age), min = 0.90, max = 1)
se <- runif(length(age), min = 0.002, max = 0.008)
# collate into data frame
data <- data.frame(age, sequence, response, accuracy, se)
# do plot
pd <- position_dodge(0.08)
plot <- ggplot(data, aes(x = sequence, y = accuracy, group = response,
colour = response))
plot <- plot + geom_errorbar(aes(ymin = accuracy - se, ymax = accuracy + se),
width = .15, size = 0.5, position = pd)
plot <- plot + geom_line(aes(linetype = response), position = pd)
plot <- plot + geom_point(aes(shape = response), size = 2.3, position = pd)
plot <- plot + scale_x_discrete(name = "Task Sequence") +
scale_y_continuous(name = "Accuracy (Proportion)")
plot <- plot + scale_shape_discrete(name = "Response") +
scale_linetype_discrete(name = "Response")
plot <- plot + facet_grid( ~ age)
plot + scale_color_manual(values = c("#999999", "#E69F00"))