library(ggplot2)
food_choices <- c("Pizza", "Pasta", "Sushi", "Caesar Salad")
counts <- c(17, 10, 8, 11)
table <- data.frame(food_choices, counts) # Create data frame
colnames(table) <- c("Food", "Count")
# Pie Chart:
ggplot(table, aes(x = "", y = Count, fill = Food)) +
geom_bar(width = 1, stat = "identity") +
coord_polar(theta = "y", start = 0) +
scale_fill_manual(values = c("Blue", "Red", "Green", "Orange")) +
labs(x = "",
y = "",
title = "Favourite Food Survey \n",
fill = "Colour Choices") +
theme(
plot.title = element_text(hjust = 0.5),
legend.title = element_text(hjust = 0.5, face = "bold", size = 10)
)
code is here. Want to change the shape from square to circle.
That is: In the output, I want to change "blue square" before "Caesar Salad" to "blue circle". Thanks
The symbol(s) used in the legend are detereminded by the key glyph of the
geomwhich in case ofgeom_baris a rectangle. But you can change that with thekey_glyph=argument of thegeom, i.e. to get circles you can usekey_glyph = "point". However, as the default point shape does not support afillaes we have to switch to a shape which supportsfillakashape=21which can be done with theoverride.aesargument ofguide_legend. Additionally I increased the size of the "points".