I use prop.table() to create a proportion table for my data. Then I wonder how should I do to plot it since there is no separate variable x and y from the function. Any hints or suggested approaches will be much appreciated!
Asked
Active
Viewed 222 times
-2
-
2It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. There's no one "right" way to plot data. You need to decide what's best for your needs. If you just have a general data visualization question, then that might be a better for for [stats.se] since that's not a specific programming question that's appropriate for Stack Overflow. – MrFlick Nov 03 '21 at 03:43
-
Thank you for pointing it out. Since the problem occurred when I was writing my assignment so I couldn't provide the data of that time, and I have not been familiar with Stack yet. Next time I will remember to ask with a concrete example – zoe Nov 27 '21 at 02:26
1 Answers
1
Just use barplot
.
# P <- prop.table(tbl, "Gender") ## prop.table is an earlier name
P <- proportions(tbl, "Gender")
barplot(P)
Data:
DF <- as.data.frame(UCBAdmissions)
tbl <- xtabs(Freq ~ Gender + Admit, DF)

jay.sf
- 60,139
- 8
- 53
- 110