我的数据集是这样的:
structure(list(title = c("Fried Anchovies with Sage", "Anchovies Appetizer With Breadcrumbs & Scallions",
"Carrots, Cauliflower And Anchovies", "Bap Story: Stir Fried Anchovies (Myulchi Bokkeum)",
"Fried Anchovies"), pricePerServing = c(5.6051, 0.8206, 4.38,
8.1122, 1.505), healthScore = c(29, 4, 63, 70, 6), readyInMinutes = c(45L,
15L, 45L, 45L, 15L), veryHealthy = c("False", "False", "True",
"True", "False"), dairyFree = c("True", "True", "True", "True",
"True"), dishType = c("lunch", "antipasti", "lunch", "lunch",
"antipasti"), healthy = c(0.752433090024331, 0.752433090024331,
0.247566909975669, 0.247566909975669, 0.752433090024331), diary = c(0.423965936739659,
0.423965936739659, 0.423965936739659, 0.423965936739659, 0.423965936739659
), percent = c(0.370250606305578, 0.370250606305578, 0.587223587223587,
0.587223587223587, 0.370250606305578)), row.names = c(NA, 5L), class = "data.frame")
我的代码是:
ggplot(foods, aes(x=veryHealthy, y=diary, width=healthy , fill = dairyFree)) +
geom_bar(position="fill", stat='identity') +
scale_x_discrete(expand = c(0, 0)) +
facet_grid(~veryHealthy, scales = "free", space = "free") +
geom_text(aes(label = percent), colour = "white")
我的第一张图片是这样的:
我想在每个条的中间制作标签,所以我使用 position = position_stack(0.5)
,修改后的代码是:
ggplot(foods, aes(x=veryHealthy, y=diary, width=healthy , fill = dairyFree)) +
geom_bar(stat='identity') +
scale_x_discrete(expand = c(0, 0)) +
facet_grid(~veryHealthy, scales = "free", space = "free") +
geom_text(aes(label = percent), position = position_stack(0.5))
我的问题不是改变高度,而是那些难看的黑线。
我应该怎么办?