Bar graph showing the structure of the game collection depending on genre and accessibility

Correlation diagram is working and looks good, but Bar graph didn't. Please help to find mistake.

Pocitacove_hry$ProdejSvet_out = Pocitacove_hry$Celkove_celosvetove_prodeje
Pocitacove_hry$HodnKritici_out = Pocitacove_hry$Hodnoceni_hry_od_kritiku

Pocitacove_hry$ProdejSvet_out[Pocitacove_hry$Celkove_celosvetove_prodeje>4.5] = NA
Pocitacove_hry$HodnKritici_out[Pocitacove_hry$Celkove_celosvetove_prodeje>4.5] = NA

Pearson1=cor(Pocitacove_hry$Celkove_celosvetove_prodeje, Pocitacove_hry$Hodnoceni_hry_od_kritiku,method = "pearson",use = "complete.obs")
Spearman1=cor(Pocitacove_hry$Celkove_celosvetove_prodeje, Pocitacove_hry$Hodnoceni_hry_od_kritiku,method = "spearman",use = "complete.obs")

Pearson2=cor(Pocitacove_hry$ProdejSvet_out, Pocitacove_hry$HodnKritici_out,method = "pearson", use = "complete.obs")
Spearman2=cor(Pocitacove_hry$ProdejSvet_out, Pocitacove_hry$HodnKritici_out,method = "spearman", use = "complete.obs")

Pearson=t(rbind(Pearson1,Pearson2))
Spearman=t(rbind(Spearman1,Spearman2))

colnames(Pearson) = c("Původní data","Očištěná data")
colnames(Spearman) = c("Původní data","Očištěná data")

tabulka = table(Pocitacove_hry$Zanr_hry, Pocitacove_hry$Pristupnost)

tabulka_rad = round(prop.table(tabulka,1)*100, digits = 0)

for (i in 1:nrow(tabulka_rad)){
tabulka_rad[i,ncol(tabulka_rad)]= 100 - sum(tabulka_rad[i,1:(ncol(tabulka_rad)-1)])
}
tabulka_rad = t(tabulka_rad)

tabulka_rad_data = as.data.frame(tabulka_rad)
colnames(tabulka_rad_data) = c("Zanr", "Pristupnost", "Cetnosti")

write.csv2(tabulka_rad,"tabulka_rad.csv")

addmargins(round(prop.table(tabulka)*100, digits=0))
addmargins(tabulka_rad,2)

write.csv2(tabulka,"tabulka_DU3.csv")
write.csv2(tabulka_rad_data, "tabulka_rad_data.csv")

ggplot(Pocitacove_hry, aes(x = HodnKritici_out, y = ProdejSvet_out)) +
geom_point(size = 3, shape = 13) +
geom_smooth(method = lm, se = FALSE, color = "cyan") +
labs(x = "Hodnocení od kritiků (%)", y = "Počet prodaných kopií ve světě - miliony") +
theme_minimal() +
theme(
axis.text = element_text(color = "black", size = 11),
axis.title = element_text(color = "black", size = 11),
plot.title = element_text(hjust = 0.5),
plot.margin = unit(c(0.5, 2, 0.5, 0.5), "cm")
) +
scale_y_continuous()

library(viridis)
library(tidyr)

Přeformátování dat pro použití s ggplot

tabulka_rad_data %>%
mutate(Cetnosti = as.numeric(Cetnosti)) %>%
ggplot(aes(x = factor(Pristupnost), y = Cetnosti, fill = Zanr)) +
geom_bar(stat = "identity", position = "stack") +
geom_text(aes(label = paste0(Cetnosti, "%")), position = position_stack(vjust = 0.5), size = 4, color = "black") +
labs(
x = "Přístupnost",
y = "Kumulativní relativní četnost (%)",
fill = "Žánr"
) +
scale_fill_viridis(discrete = TRUE) +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5),
axis.text = element_text(color = "black"),
legend.position = "top"
)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.