问题描述
我有一个大型的数据框,其中包含瑞士某些地区(“州”)的报纸信息。一个最小的,可复制的示例可能看起来像这样:
dataframe <- data.frame(canton=c("AG","AG","BE","LU","ZH","ZH"),canton_id=c(19,19,2,3,1,1),newspaper=c("AZ","ZOF","BZ","NLZ","AVU","LB"),minimum=c("1999-12-03","2000-10-03","1998-12-03","1998-01-03","2011-04-03","2002-04-03"),maximum=c("2009-09-29","2018-11-27","2017-02-14","2018-11-27"))
我需要用ggplot2绘制一个图形,该图形应与此图形相似(请忽略黑点,并认为此图形比可复制示例产生的图形大得多):
现在,我已经做了什么?我得到的最接近的是以下代码:
ggplot(dataframe) + geom_segment(aes(x=minimum,xend=maximum,y=newspaper,yend=newspaper,size = 1,color = canton))
对我的“解决方案”的最大关注:如果一个州有多个报纸,我需要将它们按该州分组,而不是按字母顺序排列。我需要考虑因素吗?
我已经咨询了以下问题:
How do you specifically order ggplot2 x axis instead of alphabetical order?
Order discrete x scale by frequency/value
如果您需要任何其他信息,请告诉我。