Я видел все ответы на этот вопрос, и я думал, что я его охватил, но что-то не получается. Мои данные содержат более 1500 строк, которые выглядят так:
![enter image description here](https://i.stack.imgur.com/aMKHV.png)
, а мой код:
library(ggplot2)
dat <- read.table("C:/Projects/....txt",
sep="\t", header=TRUE)
df<-data.frame(dat)
ggplot(df)+
df$scenario_f = factor(df$scenario, levels=c('Baseline','10% Increase','20% Increase','30% Increase',
'200-200-200','10% + 200-200-200','20% + 200-200-200',
'30% + 200-200-200','100-200-200','10% + 100-200-200',
'20% + 100-200-200','30% + 100-200-200'),ordered=TRUE)+
geom_histogram(aes(x=points),position="identity", colour="darkseagreen4",alpha=0.3, bins = 40) +
facet_wrap(.~scenario_f)+
scale_x_continuous(breaks =(seq(0,1200, by = 200))) +
scale_y_continuous(labels=comma) +
labs(x="Points",y="Number of Members")+
theme(axis.title.y = element_text(size="12"),axis.title.x = element_text(size="12"),
axis.text.x=element_text(size=10),axis.text.y=element_text(size=10))
Если я удалю утверждение
df$scenario_f = factor(df$scenario, levels=c('Baseline','10% Increase','20% Increase','30% Increase',
'200-200-200','10% + 200-200-200','20% + 200-200-200',
'30% + 200-200-200','100-200-200','10% + 100-200-200',
'20% + 100-200-200','30% + 100-200-200'),ordered=TRUE)+
Мой график выглядит следующим образом
![enter image description here](https://i.stack.imgur.com/pqjcJ.png)
Но порядок граней неправильный. Это должно быть так, как указано в операторе фактора, и я получаю следующую непонятную ошибку:
Ошибка в факторе (сценарий df $, уровни = c («Базовый уровень», «Увеличение на 10%», «20% Increase ",: нечисловой аргумент для бинарного оператора. Дополнительно: Предупреждение: несовместимые методы (" Ops.ordered "," + .gg ") для" + "