Подобно @DaveGruenewald, я получил правильные значения, используя ваш код и данные. Я заметил, что у вас есть тема (legend.position = "top"), в то время как вы показали сюжет с легендой на стороне. Это тот же код, для справки вы можете попробовать то, что у меня ниже.
То, что я использовал из вашей таблицы выше:
chart.new=dput(chart.new)
structure(list(Group = structure(c(2L, 3L, 1L, 4L, 5L, 2L, 3L,
1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L,
4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L,
5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L,
2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L,
3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L,
1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L,
4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L,
5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L, 2L, 3L, 1L, 4L, 5L
), .Label = c("Cephalosporins", "Macrolides", "Penicillins",
"Quinolones", "Tetracyclines"), class = "factor"), Country = structure(c(27L,
27L, 27L, 27L, 27L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L,
6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L,
9L, 9L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 12L,
12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L,
14L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 17L, 17L,
17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L,
20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L,
22L, 22L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 25L,
25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L), .Label = c("Belgium",
"Bulgaria", "Cyprus", "Czech", "Denmark", "Estonia", "Finland",
"France", "Germany", "Greece", "Hungary", "Iceland", "Ireland",
"Italy", "Lativa", "Lithuania", "Luxembourg", "Malta", "Netherlands",
"Norway", "Poland", "Portugal", "Slovenia", "Spain", "Sweden",
"UK", "X3"), class = "factor"), DailyDosage = c(2.85, 6.64, 1.7,
1.36, 1.19, 2.62, 16.28, 1.59, 2.69, 2.1, 2.49, 8.05, 2.32, 1.99,
1.71, 2.86, 14.43, 5.41, 4.1, 3.27, 3.25, 7.6, 1.62, 1.22, 2.27,
2.34, 10.29, 0.03, 0.51, 1.7, 2.06, 4.22, 0.88, 0.81, 1.89, 1.23,
6.61, 2.33, 0.88, 4.09, 2.63, 15.62, 2.67, 2, 3.16, 2.09, 4.1,
2.61, 1.51, 2.74, 8.55, 12.87, 8.91, 2.89, 2.31, 2.42, 6.69,
1.92, 1.97, 1.38, 1.4, 12.08, 0.62, 1.02, 5.05, 3.63, 10.65,
1.21, 0.91, 2.6, 4.98, 14.55, 2.55, 3.45, 0.53, 1.03, 5.59, 0.57,
0.91, 2.38, 1.44, 6.99, 0.8, 0.83, 1.38, 3.46, 13.96, 4.18, 2.94,
2.04, 2.97, 9.8, 5.04, 1.79, 1.02, 1.31, 4.36, 0.04, 0.87, 2.66,
1.55, 6.77, 0.12, 0.54, 2.77, 2.89, 9.43, 2.44, 1.23, 2.1, 3.37,
12.08, 1.81, 2.97, 0.71, 1.89, 9.67, 0.4, 1.1, 0.04, 1.88, 12.64,
1.56, 2.54, 0.7, 0.43, 7.09, 0.2, 0.77, 3.33, 2.71, 8.6, 0.55,
0.46, 4.15)), class = "data.frame", row.names = c(NA, 135L))
Проверка chart.new:
str(chart.new)
'data.frame': 135 obs. of 3 variables:
$ Group : Factor w/ 5 levels "Cephalosporins",..: 2 3 1 4 5 2 3 1 4 5 ...
$ Country : Factor w/ 27 levels "Belgium","Bulgaria",..: 27 27 27 27 27 1 1 1 1 1 ...
$ DailyDosage: num 2.85 6.64 1.7 1.36 1.19 ...
Использование цветов по умолчанию:
ggplot(data=chart.new ,aes(x = Country, y = DailyDosage, fill = Group, group = Group))+
geom_bar(stat = "identity")+ coord_flip() +
labs(title = "Antibiotic Consumption by Group ")+
theme(legend.position = "top")