simpan = read.table("data3.5.csv", header = TRUE, sep = ",")
simpan
## Produk Jumlah
## 1 A 12
## 2 B 5
## 3 C 8
## 4 D 20
Jumlah = simpan$Jumlah
Produk = simpan$Produk
pie(simpan$Jumlah, labels = simpan$Jumlah,
main = "Data Penjualan Produk A, B, C, dan D",
col = heat.colors(4))
colors = heat.colors(4)
legend(1, 0.5, c("Produk A", "Produk B", "Produk C", "Produk D"),
cex = 0.8, fill = colors)

Persen = round(simpan$Jumlah / sum(simpan$Jumlah) * 100, 4)
Persen = paste(Persen, "%", sep = "")
pie(simpan$Jumlah, labels = Persen,
main = "Data Penjualan Produk A, B, C, dan D",
col = c("darkblue", "orange", "yellow", "red"))
colors = c("darkblue", "orange", "yellow", "red")
legend(1, 0.5, c("Produk A", "Produk B", "Produk C", "Produk D"),
cex = 0.8, fill = colors)

library(ggplot2)
library(grid)
library(gridExtra)
blank_theme = theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(size = 14, face = "bold")
)
pie = ggplot(simpan, aes(x = "", y = Jumlah, fill = Produk)) +
geom_bar(width = 1, stat = "identity", position = position_stack(reverse = TRUE)) +
coord_polar("y", start = 0)
pie + blank_theme +
geom_text(aes(label = Jumlah),
position = position_stack(vjust = 0.5, reverse = TRUE), size = 5)

Persen2 = round(simpan$Jumlah / sum(simpan$Jumlah) * 100, 2)
Persen_label = paste(Persen2, "%", sep = "")
pie + blank_theme +
geom_text(aes(label = Persen_label),
position = position_stack(vjust = 0.5, reverse = TRUE), size = 5) +
scale_fill_manual(values = heat.colors(4))
