I'm super new to R and wanted to make a pie chart of the results found from a 6 faced die. From what I understand, this is supposed to throw the 6-faced die 500 times, and then map out the results in a pie chart. It seems fairly simple, but the pie chart splits into 500 ways. What am I doing wrong?
die <- 1:6
result <- sample(die, size = 500, replace = TRUE)
pie(result, labels = die)
?table; do your plot on the output of that for a display of counts (or scale that by the total count for proportions). (A pie chart is a poor choice for this by the way; I'd typically use a variant ofplot(table(...))to show such results.) – Glen_b Mar 14 '23 at 22:20pie()is "Pie charts are a very bad way of displaying information." – Sal Mangiafico Mar 14 '23 at 22:38Revery day for over a decade, have posted a thousandRsolutions here on CV, and have never once invokedpie. (But see https://stats.stackexchange.com/a/451376/919 ;-).) Following @Glen_b's recommendation, I looked atpie(table(sample.int(6, 500, replace = TRUE))). Rather pretty -- nice pastel colors rarely seen in any otherRfunctions -- and quite useless! For the record, this function defaults to a cycle of six colors,c("white", "lightblue", "mistyrose", "lightcyan", "lavender", "cornsilk"). – whuber Mar 14 '23 at 22:56dieis both the population data and the labels for the chart. An example with an unfair die:die <- c(1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6); result <- sample(die, size = 500, replace = TRUE); Table = table(result); Table; pie(Table, labels=labels(Table)[[1]]); round(prop.table(table(result)), 2)– Sal Mangiafico Mar 14 '23 at 23:00die<-rep(1:6,c(5, 4, 4, 3, 3, 2))would save some typing, alternatively just directly gosample(6,500,replace=TRUE,p=c(5, 4, 4, 3, 3, 2))– Glen_b Mar 14 '23 at 23:04