美文网首页
R学习笔记 列联表+散点图转曲线图

R学习笔记 列联表+散点图转曲线图

作者: 扩容_ | 来源:发表于2019-10-17 20:54 被阅读0次

1、CrossTable() spline() plot()

table_24 <- CrossTable(data_3$huofenduan,data_3$xs,digits = 0,prop.r = T,prop.c = F, prop.t = F,prop.chisq = F,chisq = T,format = "SAS")

table_241 <- as.data.frame(table_24$prop.row)

huofen.prop <- table_241[6:10,3]*100

huofen_xs <- data.frame(huofen,huofen.prop)#plot(huofen_xs$huofen,huofen_xs$huofen.prop,type = "b")

sp <- spline(huofen_xs$huofen,huofen_xs$huofen.prop)

plot(sp,type = "l",main = "xs_huofen")

2、优化代码,批量作图

library(gmodels)

curve1 <- function(data1, data2){

    table_t1 <- CrossTable(data1,data2,digits = 0,prop.r = T,prop.c = F, prop.t = F,prop.chisq = F,chisq = T,format = "SAS")

    table_t2 <- as.data.frame(table_t1$prop.row)

    prop <- table_t2[6:10,3]*100   

    zuofen <- c(1:5) zuofen_t <- data.frame(zuofen,prop) #plot(zuofen_xs$zuofen,zuofen_xs$zuofen.prop,type = "b")

sp <- spline(zuofen_t$zuofen,zuofen_t$prop)

ploti <- plot(sp,type = "l")

return(ploti)}

c1 <- c("gxy","zf","xjt","xs")

c2 <- c("zuofenduan","huofenduan","fenbiduan")

for (i in 1:4) {

    for(j in 1:3) {

        curve1(data_3[,c1[i]],data_3[,c2[j]])

        titlet <- paste(c1[i],c2[j],sep = "_")

        title(main = titlet) }}

相关文章

网友评论

      本文标题:R学习笔记 列联表+散点图转曲线图

      本文链接:https://www.haomeiwen.com/subject/vntbmctx.html