SSブログ

R: ggplot2: scale_manual その2 [統計]

scale_manual系のつづき。

Rplot002.png
Rplot003.png

コード
library(ggplot2)

set.seed(123)
n <- 100

x <- runif(n, 0, 1)
y <- runif(n, 0, 1)
z <- runif(n, 0, 1)
c <- ifelse(z < 0.5, 1, 2)
d <- data.frame(x = x, y = y, z = z, c = as.factor(c))

p2 <- ggplot(d) +
      geom_point(aes(x = x, y = y, colour = c),
                 size = 4, alpha = 0.67) +
      scale_colour_manual(name = "z",
                          breaks = c(1, 2),
                          values = c("orange", "blue"),
                          labels = c("z < 0.5", "z ≥ 0.5")) +
      xlim(0, 1) + ylim(0, 1) 
png("Rplot002.png", width = 520, height = 480)
print(p2)
dev.off()

p3 <- ggplot(d) +
      geom_point(aes(x = x, y = y, size = c),
                 alpha = 0.67) +
      scale_size_manual(name = "z",
                        breaks = c(1, 2),
                        values = c(2, 4),
                          labels = c("z < 0.5", "z ≥ 0.5")) +
      xlim(0, 1) + ylim(0, 1) 
png("Rplot003.png", width = 520, height = 480)
print(p3)
dev.off()



タグ:R ggplot2
nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 0