2017-05-11 1 views
1

私は階乗グラフを持っており、グラフの各ライン/ポイントで選択した色をコントロールしたいと考えています。私はオンラインリソースを調べて、ggplot2の中で+scale_color_manual()関数を使うべきであることを見てきました。ggplot2内のポイントのマニュアルカラー

これは、所望の出力を作成しますが、それはまた、私はしたくない余分な凡例を作成します。 enter image description here

余分な凡例を作成せずに回線を介して手動制御を達成するための正しい方法は何ですか、してください?

コード:

# 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")) 

答えて

2

次の2つの伝説を結合したい場合は、単にscale_shape_discrete()scale_linetype_discrete()

ggplot(data, aes(x = sequence, y = accuracy, group = response, 
      colour = response)) + 
     geom_errorbar(aes(ymin = accuracy - se, ymax = accuracy + se), 
         width = .15, size = 0.5, position = pd) + 
     geom_line(aes(linetype = response), position = pd) + 
     geom_point(aes(shape = response), size = 2.3, position = pd) + 
     scale_x_discrete(name = "Task Sequence") + 
     scale_y_continuous(name = "Accuracy (Proportion)") + 
     scale_color_manual(values = c("#999999", "#E69F00")) + 
     facet_grid(~ age) 

enter image description here

を削除することができます
1

すべての伝説を削除する+ theme(legend.position="none")を追加します。

enter image description here

使用scale_color_manual(values = c("#999999", "#E69F00"), guide=FALSE)あなただけの二凡例を削除する場合。

enter image description here

関連する問題