我试图让我的代码在每个条形图的顶部输出百分比。现在,下面显示的百分比是错误的。我的代码结合了标签 1 和 2 以及标签 3 和 4,然后在不正确的边上输出这些数字。
是否有正确标记这些条的功能?我包括我的代码、.csv 文件中的数据和当前的可视化。
library(ggplot2)
library(reshape)
library(likert)
library(dplyr)
setwd("~/Desktop/")
df <- read.csv("Likert_Test.csv")
df[2:3] <- lapply(df[2:3], as.factor)
colnames(df)[2:3] <- c("cake?", "cookies?")
df[2:3] <- lapply(df[2:3], factor, levels = 1:4)
myplot <- likert(df[2:3], grouping = df$gender)
plot(myplot, centered = FALSE, col = c("#0A2240", "#3474DA", "#C1A783", "#323A45")) +
scale_y_continuous(labels = function(x) paste0(x, "%")) +
ggtitle("How much do you like...") +
theme(legend.title = element_blank(),
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5))
gender cake cookies
Male 3 1
Male 2 2
Male 2 2
Male 4 2
Male 2 3
Male 2 3
Male 2 3
Male 1 1
Male 4 2
Female 1 1
Female 3 1
Female 3 4
Female 3 4
Female 1 1
Female 4 3
Female 4 2
Female 3 2
Female 2 1
Female 3 1