У меня проблема с правильным добавлением текстовых элементов на график в некоторых моих диаграммах. Я использую ggplot2 и + labs(...), но в мой график включены только некоторые элементы.
Это один из графиков:
colnames(dane.trust)[1] = "Country" #GEO.INDIC_WB
w5 <- ggplot(dane.trust, aes(x = reorder(Country, Trust.Index), y = Trust.Index, fill=Country)) + scale_fill_brewer(palette = "Set2")
w5 + geom_bar(stat="identity") + #guides(fill=FALSE) +
geom_text(data=dane.trust[,c(1,6)], label = round(Trust.Index, digits = 2),vjust = -0.5, aes(inherit.aes = TRUE, fontface=2)) +
theme_bw() + labs(x="", y="Average Rating (0-10)", title = "Overall trust levels", subtitle="Index of trust to political and legal systems, police and others") +
theme(title = element_text(face = "bold", color = "black"), axis.title = element_text(face = "bold", color = "black"), panel.grid.major.x = element_blank())
Заголовок, x.label и y.label работают нормально, но я не вижу ни подзаголовка, ни подписи.
Ошибки нет, просто тех элементов нет.
Кто-нибудь знает, в чем может быть проблема?
EDIT1: вот вывод > dput(dane.trust)
structure(list(Country = structure(1:5, .Label = c("Bulgaria",
"Hungary", "Poland", "Romania", "Slovakia"), class = "factor"),
Trust.in.the.political.system = c(2.6, 4.5, 3.5, 4.8, 3.5
), Trust.in.the.police = c(3.6, 5.7, 5.2, 6.4, 4.4), Trust.in.others = c(4.2,
5.3, 6, 6.4, 5.8), Trust.in.the.legal.system = c(3, 5.1,
4.2, 5.8, 3.6), Trust.Index = c(3.35, 5.15, 4.725, 5.85,
4.325)), .Names = c("Country", "Trust.in.the.political.system",
"Trust.in.the.police", "Trust.in.others", "Trust.in.the.legal.system",
"Trust.Index"), row.names = c(NA, -5L), class = "data.frame")
EDIT2: я только что проверил свой исходный код на другом компьютере, он сработал. Что может быть причиной этого?
Хорошо, после переустановки R и RStudio все заработало, всем спасибо за ответы :).
dput(dane.trust)
в блоке кода. - person hrbrmstr   schedule 23.11.2018ggplot2
вы используете? - person JdeMello   schedule 23.11.2018geom_text(...)
наgeom_text(vjust = -0.5, aes(fontface=2), label = dane.trust$Trust.Index)
. Аргументlabel
вgeom_text()
может оценивать толькоTrust.Index
внутри аргументаaes()
. Вам нужно указать вектор в аргументеlabel = ...
внеaes()
. Таким образом, вы можете сделать либоgeom_text(label = dane.trust$Trust.Index, ...)
, либоgeom_text(data = dane.trust[, c(1, 6)], ..., aes(label = Trust.Index))
. - person JdeMello   schedule 23.11.2018