我有一个生日数据框,想按最早日期到最远日期排序。他们似乎不想按日期顺序绘图。
以下是数据框:
df <- data.frame(name = c("Sara", "Joe", "Matt", "Katie", "Ryan", "Sam"), date = c("2003-03-27", "2004-05-16", "2001-02-02", "2004-05-16", "2002-09-03", "2003-1-17"))
到目前为止,我尝试过的是:
ggplot(df[order(df$date),]) +
geom_bar(aes(x=name, y=date), color = 'black', fill = 'blue', stat = 'identity')
答案 0 :(得分:0)
尝试:
df$name <- with(df, factor(name, levels = name[order(date, name)]))
ggplot(df) +
geom_bar(aes(x=name, y=date), color = 'black', fill = 'blue', stat = 'identity')