data.table
グループ化されたデータでも機能するソリューションを追加したかっただけです。
library(ggplot2)
library(data.table)
# Creates data from the Weibull distribution
weib_dt <- function(x = seq(0, 4.0, 0.01), w_shape = 1, w_scale = 1) {
y = dweibull(x, shape = w_shape, scale = w_scale)
data.table("shape" = as.factor(w_shape), "scale" = as.factor(w_scale), "x" = x, "y" = y)
}
dt_a <- weib_dt(w_shape = 0.5)
dt_b <- weib_dt(w_shape = 1.0)
dt_c <- weib_dt(w_shape = 2.0)
# Bind multiple Weibull samples together, created from different parametrizations
dt_merged <- rbindlist(list(dt_a, dt_b, dt_c))
# Create the plot, using all the points for the lines, and only 9 points per group for the points.
ggplot(dt_merged, aes(x, y, group=shape, color=shape)) +
coord_cartesian(ylim = c(0, 1.5)) +
geom_line() +
geom_point(data=dt_merged[, .SD[floor(seq(1, .N, length=9))], by=shape],
aes(x, y, group = shape, color = shape, shape = shape))
ここでの秘訣は、seq
上記の提案された解決策と同様にを使用することですが、今回はグループ内で(を使用して.SD
)実行されます。現在、パフォーマンスが低下する可能性があることに注意してください。これが遅い場合は.SD
、より詳細なものを使用できます。dt[dt[, ..., by =shape]$V1]
これにより、次の出力が作成されます。
