我正在嘗試使用 ggplot2 用我自己的資料復制這個數字。

就我而言,我現在不關心顏色和圖例,我只需要顯示一年內新存盤庫的數量和創建日期的 cdf(累積分布函式)(帶有雙 y軸,將 1.0 值定位在右上角,如示例中)
到目前為止,我得到了這段代碼:
repo.count <- read.csv("http://pastebin.com/raw.php?i=PfUgyrt0",sep=",")
repo.count$createdAt <- as.Date(repo.count$createdAt)
ggplot(data = repo.count, aes(x = createdAt))
geom_histogram(colour = 1, fill = "white", position="identity")
xlab('Date')
ylab('# New Repositories')
ggtitle('')
scale_x_date(labels = scales::date_format("%Y-%b"),
breaks = by_month(date.groups$createdAt,2))
scale_y_continuous(sec.axis = sec_axis(~. / max(repo.count$total),
name = "Cumulative distribution"))
theme(axis.text.x = element_text(angle=90)) stat_ecdf(size=1)
但這遠非我想要達到的目標:

任何幫助都感激不盡。
uj5u.com熱心網友回復:
我想知道您是否可能不是在尋找這樣的直方圖,而只是每天新回購的條形圖和指示累積回購的線?如果是這樣,請使用geom_col代替geom_histogram,并將 y 變數指定為repositories
ggplot(data = repo.count, aes(x = createdAt, y = repositories))
geom_col(fill = "green4", color = NA)
geom_step(aes(y = total / 100))
xlab('Date')
ylab('# New Repositories')
ggtitle('')
scale_x_date(labels = scales::date_format("%Y-%b"),
date_breaks = 'month')
scale_y_continuous(sec.axis = sec_axis(~. * 100,
name = "Cumulative repos"))
theme_classic(base_size = 16)
theme(axis.text.x = element_text(angle = 90)

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/482734.html
