Thanks @Hermes I tried to run the code you pasted above, but its showing an error "Error: 'label_percent' is not an exported object from 'namespace:scales'.
dt<- structure(list(modality = structure(c(1L, 2L, 3L, 5L, 4L), .Label = c("Appearance",
"Aroma", "Flavor", "Hedonic", "Texture"), class = "factor"),
First_response = c(201L, 8L, 107L, 151L, 282L),
Second_response = c(72L, 17L, 148L, 225L, 260L),
Third_response = c(54L, 17L, 177L, 220L, 360L),
Fourth_response = c(46L, 24L, 168L, 198L, 356L ),
Fifth_response = c(39L, 13L, 122L, 150L, 402L),
Frequency = c(749L, 722L, 828L, 792L, 726L)), class = "data.frame",
row.names = c(NA,-5L))
dt1<-data.table(dt)[,.SD/Frequency,by=c("Frequency","modality"),.SDcols=2:6]
#> Error in data.table(dt): could not find function "data.table"
dat <- melt(dt1,id.vars = c("Frequency","modality"),variable.name = "Response", value.name = "Percentage",variable.factor=TRUE)
#> Error in melt(dt1, id.vars = c("Frequency", "modality"), variable.name = "Response", : could not find function "melt"
dat[,ggplot(.SD,aes(x = Response, y = Percentage, fill = modality)) +
geom_col(position = "dodge") +
geom_text(aes(label = scales::percent(Percentage, accuracy = 0.1)),
position = position_dodge(width=0.9), vjust = -0.25) +
labs(x = NULL, y = "Percentage") +
scale_y_continuous(labels = scales::label_percent()) +
scale_fill_brewer('Variables', palette='Spectral') +
theme_bw() +
theme(legend.title = element_blank(),
legend.position = c(.3, .95),
legend.direction = "horizontal"),]
#> Error in eval(expr, envir, enclos): object 'dat' not found
Created on 2020-04-11 by the reprex package (v0.3.0)