我想添加一個條件geom_point大小,我已經粘貼下面的示例。當n_in_stat大於等於4時,我希望geom_point大小爲2,當n_in_stat小於4時size = 5。我嘗試在geom_point中放置一個ifelse語句,但是失敗了。也許我不能在這裏包含邏輯運算符,我必須在data.frame中創建一個新列,並將其大小設置爲?如何將條件添加到geom_point大小?
geom_point(大小= ifelse(n_in_stat < 4,5,2))+#試圖用ifelse集大小
geom_point(AES(大小= n_in_stat))+#原始線性縮放
library(ggplot2)
# Create a long data.frame to store data...
growth_series = data.frame ("read_day" = c(0, 3, 9, 0, 3, 9, 0, 2, 8),
"series_id" = c("p1s1", "p1s1", "p1s1", "p1s2", "p1s2", "p1s2", "p3s4", "p3s4", "p3s4"),
"mean_od" = c(0.6, 0.9, 1.3, 0.3, 0.6, 1.0, 0.2, 0.5, 1.2),
"sd_od" = c(0.1, 0.2, 0.2, 0.1, 0.1, 0.3, 0.04, 0.1, 0.3),
"n_in_stat" = c(8, 8, 8, 8, 7, 5, 8, 7, 2)
)
# Plot using ggplot...
ggplot(data = growth_series, aes(x = read_day, y = mean_od, group = series_id, color = series_id)) +
geom_line(size = 1.5) +
geom_point(aes(size = n_in_stat)) +
geom_errorbar(aes(ymin = mean_od - sd_od, ymax = mean_od + sd_od), size = 1, width = 0.3) +
xlab("Days") + ylab("Log (O.D. 730 nm)") +
scale_y_log2() +
scale_colour_hue('my legend', breaks = levels(growth_series$series_id), labels=c('t1', 't2', 't3'))
你可能還需要'+ scale_size_identity' – hadley
奇怪,這給:在EVAL錯誤(表達式,ENVIR,enclos):找不到函數 「FF」 當我調用另一個函數內ggplot。 – gkcn