Как превратить таблицы частот в гистограмму с накоплением в процентах - PullRequest
0 голосов
/ 04 июля 2019

Я хотел бы создать столбчатую диаграмму в процентах с базой R. Есть ли способ автоматизировать это?

 #calculate frequencies     
 table(initial$mth1)
 table(initial$mth2) 
 table(initial$mth3) 
 table(initial$mth4) 
 table(initial$mth5) 
 table(initial$mth6) 
 table(initial$mth7)
 table(initial$mth8)

 initialmth <- structure(list( #had to round some nums below for 100% bar

 A = c(49, 24, 9, 10, 4), 
 B = c(11, 16, 23, 28, 18),
 C = c(35, 34, 17, 9, 1),
 D = c(6, 6, 15, 37, 32), 
 E = c(29, 37, 10, 12, 8),
 F = c(7, 12, 15, 36, 26),
 G = c(5, 4, 9, 29, 49),
 H = c(4, 5, 18, 30, 39 )),

.Names = c("Math has been my worst subject ",
         "I would consider a career that uses math ",
         "Math is hard for me",
         "I am the type of student to do well in math",
         "I cannot do a good job with math",
         "I could do advanced work in math",
         "I can get good grades in math",
         "I am good at math"
), 
 class = "data.frame", 
 row.names = c(NA, -5L)) #4L=number of numbers in each letter vector#

 attach(initialmth)
 print(initialmth)


 # barplot
 colors <- c("slategray1", "slategray3","steelblue3", "dodgerblue4")
 par(mar=c(0, 17, 1, 2.1)) # this sets margins to allow long labels
 byc <- barplot(as.matrix(initialmth, horiz=TRUE, col=colors, main="N=96", 

           border=FALSE, las=1, xaxt='n',
       ylim = range(0, 12), xlim = range(0, 100)))

Я хочу взять частоты, рассчитанные выше, и превратить их в гистограмму в процентах. Есть ли способ автоматизировать этот процесс в базе R?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...