gpt4 book ai didi

r - 有关情节的一般性问题

转载 作者:行者123 更新时间:2023-12-04 05:13:15 25 4
gpt4 key购买 nike

使用R,我绘制了类似于this的阴影线图。我想在R中执行以下4件事

  • 添加图例,如链接中所示。
  • 将x轴名称替换为delta的希腊符号
  • 提及绘图上的各个交点。例如,在x = 0.75处,一些曲线与x轴相交,我想将0.75值放在该点附近。
  • 如果您看到曲线,则它们不平滑。如何使它们光滑?即使是excel,也能绘制出更加平滑的曲线。

  • 如何实现呢?

    这是情节。

    以下代码用于绘制图。
    plot(NA,xlim=c(0,1),ylim=c(0,1),xlab="delta",ylab="K", xaxs="i",yaxs="i") # Empty plot
    a1 <- curve((x+x^7-x^2-x^4)/(1+x-x^3-x^4), from=0, n=450000, add = TRUE) # First curve
    a2 <- curve((x^2+x^3-x-x^5)/(x+x^2), to=0.9, n=45000, add = TRUE)
    a3 <- curve((x+x^7-x^2-x^4)/(1+x-x^2-x^3-x^4+x^7),from=0, n=45000, add = TRUE)
    a4 <- curve((x+x^8-x^3-x^5)/(x+x^8-x^3-x^5+1-x^4),from=0, to=0.9, n=45000, add = TRUE)
    a5 <- curve((x+x^8-x^3-x^5)/(1+x-x^5-x^4),from=0, n=45000, add = TRUE)
    a6 <- curve((x+x^2-x^4-1)/(x-x^4), to=0.84, n=45000, add = TRUE)
    a7 <- curve((x+x^6-x^3-x^4)/(1+x-x^3-x^4), from=0.83 ,to=1, n=45000, add = TRUE)
    a8 <- curve((1+x^7-x^2-x^4)/(1+x^3-x-x^4), from=0.819, n=45000, add = TRUE)
    a9 <- curve((x)/(1+x), n=45000,from=0.819, to =1, add = TRUE)


    names(a1) <- c('xA1','yA1')
    names(a2) <- c('xA2','yA2')
    names(a3) <- c('xA3','yA3')
    names(a4) <- c('xA4','yA4')
    names(a5) <- c('xA5','yA5')
    names(a6) <- c('xA6','yA6')
    names(a7) <- c('xA7','yA7')
    names(a8) <- c('xA8','yA8')
    names(a9) <- c('xA9','yA9')


    with(as.list(c(a1,a2,a3,a4,a5,a6,a7,a8,a9)),{

    idA <- yA3 >=0
    idB <- yA2 >=0 & yA2 <= yA4
    idC <- yA4 >= yA2

    idD <- yA5 >=0

    idE <- yA6 >=0 & yA6 <= yA7
    idF <- yA7 <= yA6

    idG <- yA8 >=0 & yA8 <= yA9
    idH <- xA9 >= xA8 & xA9 >0.8

    idI <- xA1 >=0 & xA1 <= 0.755
    idJ <- xA3 >=0 & xA3 <= 0.755



    polygon(x = c(xA3[idA],xA2[idB],rev(xA4[idC])),
    y = c(yA3[idA],yA2[idB],rev(yA4[idC])),
    density=20, angle=90, border=NULL)

    polygon(x = c(xA5[idD],1,1,0),
    y = c(yA5[idD],0,1,1),
    density=20, angle=0, border=NULL)

    polygon(x = c(xA6,xA7),
    y = c(yA6,yA7),
    density=20, angle=45, border=NULL)

    polygon(x = c(rev(xA8[idG]),xA9[idH],1),
    y = c(rev(yA8[idG]),yA9[idH],0),
    density=20, angle=135, border=NULL)

    polygon(x = c(xA1[idI],rev(xA3[idJ])),
    y = c(yA1[idI],rev(yA3[idJ])),
    col="black", border=NULL)


    })

    最佳答案

    layout(matrix(c(1,2),nrow=1),
    width=c(4,1)) #Divide your plotting region in two inequal part
    par(mar=c(5,4,4,0)) #Get rid of the margin on the right side
    plot(NA,xlim=c(0,1),ylim=c(0,1),
    xlab=expression(delta),ylab="K", xaxs="i",yaxs="i") # Here's your delta
    a1 <- curve((x+x^7-x^2-x^4)/(1+x-x^3-x^4), from=0, n=450000, add = TRUE)

    ...

    par(mar=c(5,0,4,2)) #No margin on the left side
    plot(c(0,1),type="n", axes=F, xlab="", ylab="") #Empty plot
    legend("top",legend=c("1","2","3","4","5"),
    density=c(20,20,20,20,NA), angle=c(90,0,45,135,NA),
    col=c(NA,NA,NA,NA,"black"), bty="n", cex=1.5)

    对于要标记的点,可以使用 text(或 mtext)函数“以编程方式”完成,也可以使用 locator进行交互。

    编辑:另外(正如我在评论中所说),这也可以将您的图例放在绘图区域之外,并且可能更简单:
    par(mar=c(5,4,4,8))
    plot(NA,xlim=c(0,1),ylim=c(0,1),
    xlab=expression(delta),ylab="K", xaxs="i",yaxs="i") # Here's your delta
    a1 <- curve((x+x^7-x^2-x^4)/(1+x-x^3-x^4), from=0, n=450000, add = TRUE)

    ...

    legend(1,1,legend=c("1","2","3","4","5"),
    density=c(20,20,20,20,NA), angle=c(90,0,45,135,NA),
    col=c(NA,NA,NA,NA,"black"), bty="n", cex=1.5, xpd=TRUE)

    关于r - 有关情节的一般性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15431924/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com