我遇到了用這些數據給分組的dotplots着色的麻煩(奇怪的是,我無法用ggplot2
附帶的數據集中的一個重現該問題,因此我對額外的步驟表示歉意)。如何在ggplot2中按組來繪製彩色dotplots?
data <- data.frame(
Period = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L),
Rate = c(0, 10, 10, 100, 20, 10, 20, 10, 5, 100, 0, 50, 50, 100, 20, 100, 0, 5, 5, 0, 0, 50, 10, 100, 15, 50, 0, 0, 5, 0, 100, 50, 0, 100, 0, 50, 0, 0, 5, 0, 100, 100, 50, 100, 0, 0, 0, 0, 5, 100, 100, 0, 0, 100, 0, 0, 0, 0, 0, 0, 100, 0, 0, 100, 0, 100, 0, 0, 100, 10, 100, 0, 0, 100, 0, 10, 5, 0, 100, 0, 100, 0, 100, 100, 0, 10, 5, 0, 0, 100, 100, 0, 100, 100, 30, 10, 10, 100, 0, 100, 100, 0, 0, 0, 10, 10, 0, 10, 100, 50, 0, 0, 100, 0, 0, 10, 20, 100, 100, 100, 0, 60, 0, 0, 0, 100, 50, 100, 100, 100, 100, 100, 20, 0, 0, 20, 100, 10, 0, 0, 100, 100, 30, 0, 0, 10, 100, 0, 0, 0),
Subject = c("1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6", "1", "10", "11", "12", "13", "14", "15", "3", "5", "6")
)
g <- ggplot(data = data, mapping = aes(x = factor(Period), y = Rate, fill = Subject, group = Period))
g + geom_dotplot(binwidth = 1, binaxis = "y", stackdir = "center")
這是所有罰款,只是奇怪的是,該點不保留fill=Subject
顏色。如何爲Subject
打上顏色?
更新
沒有group = Period
,被建議在評論中,填充顏色被保留,但沒有一個真正的點陣圖 - 所有的點重疊。
你只需要刪除'組= Period' – beetroot
是的,但沒有'組= Period',它不是一個真正的點陣圖 - 他們都重疊。查看更新的問題。 – maxheld
does'position =「dodge」'help? – beetroot