线之间的阴影区域; ggplot

我目前正试图在绘图中的两条线之间的阴影区域着色。 这两行显示了95%-CI的上限和下限(手动计算)。 由于数据是长格式,因此我不知道它是如何工作的。

非常感谢!

我的代码如下:

saisonesiegFavgLT = data.frame(Saison0719,EsiegFavgT,ciTobergrenze,ciTuntergrenze,EsiegFavgL,ciLobergrenze,ciLuntergrenze)

saisonesiegFavgLTlong = gather(saisonesiegFavgLT,Variable,Wert,2:7)

ggplot(saisonesiegFavgLTlong,aes(x=Saison0719,y=Wert,color=Variable))+ 
geom_line()+
geom_vline(xintercept=2011,size = 0.35)+
scale_y_continuous(name="Gewinnwahrscheinlichkeit",limits = c(0.55,0.775),breaks=c(0.55,0.575,0.6,0.625,0.65,0.675,0.7,0.725,0.75))+
scale_x_continuous(name = "Saison",limits = c(2007,2018),breaks = c(2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018))+
ggtitle("Gewinnwahrscheinlichkeit mit Konfidenzintervall")+
theme(panel.background = element_rect(fill = "white",colour = "black"))+   theme(panel.grid.major = element_line(size = 0.25,linetype = 'solid',colour = "light grey"))+
theme(axis.ticks = element_line(size = 1))+
theme(plot.title = element_text(lineheight=.8,face="bold"))+  scale_color_manual(values=c("grey80","grey80","grey40","red","blue"))   
saisonesiegFavgLTlong <-
structure(list(Saison0719 = c(2007,2018,2019,2007,2019),Variable = c("EsiegFavgT","EsiegFavgT","ciTobergrenze","ciTuntergrenze","EsiegFavgL","ciLobergrenze","ciLuntergrenze","ciLuntergrenze"
),Wert = c(0.638927795928336,0.698588187947984,0.706230083587847,0.707126891565955,0.699203318195154,0.693360727135652,0.687412868319888,0.687450746141389,0.690637150540309,0.693002300477765,0.701409867328994,0.690955678315586,0.701316603798209,0.7380033,0.7581055,0.7336691,0.7160483,0.7179448,0.7002121,0.69301,0.6934737,0.6974439,0.7000579,0.7108203,0.6982045,0.746395,0.5679567,0.6614517,0.6942799,0.6910243,0.6915419,0.6856829,0.6764988,0.6793202,0.6810342,0.6876637,0.6924067,0.6801805,0.6525103,0.679381874197023,0.681149895302252,0.680447320039109,0.68006830661108,0.67862952569516,0.678008783433529,0.678318569398466,0.680982606038272,0.681764982799431,0.679404748114889,0.682053794287606,0.681870613272628,0.68572137704311,0.694119,0.6853184,0.6824217,0.6897519,0.7081499,0.6832167,0.7053931,0.6974306,0.6851235,0.6929936,0.7125557,0.6946072,0.6966152,0.668361,0.6686594,0.6772183,0.6420841,0.6562843,0.6715409,0.665196,0.6613874,0.6657847,0.6558008,0.6683817,0.6762716,0.6768077)),row.names = c(NA,-78L),class = "data.frame")
mj5an 回答:线之间的阴影区域; ggplot

您需要的是geom_ribbon,为此,您需要定义ymin(下限)和ymax(上限)。现在,您无法从长格式中读取此信息。不确定要如何标记图形,因此,我展示的第一个解决方案是无需过多更改即可快速修复的问题:

# had to do this to get your data back
df<- spread(saisonEsiegFavgLTlong,Variable,Wert)
# put your L in one frame and T in another frame
# give each of them a group
df_L <- df[,c("Saison0719","EsiegFavgL","ciLobergrenze","ciLuntergrenze")]
colnames(df_L) <- c("Saison0719","EsiegFavg","obergrenze","untergrenze")
df_L$group = "EsiegFavgL"
df_T <- df[,"EsiegFavgT","ciTobergrenze","ciTuntergrenze")]
colnames(df_T) <- c("Saison0719","untergrenze")
df_T$group = "EsiegFavgT"

# combine,and we create a similar group,used to label your CI
plotdf <- rbind(df_L,df_T)
plotdf$ci_group <- sub("EsiegFavg","CI_",plotdf$group)

#plot like before

ggplot(plotdf,aes(x=Saison0719,y=EsiegFavg))+
geom_line(aes(col=group)) + 
geom_ribbon(aes(ymin=untergrenze,ymax=obergrenze,fill=ci_group),alpha=0.4,linetype="dotted",col="grey60") + 
scale_color_manual(values=c("red","blue"))+
scale_fill_manual(values=c("grey80","grey40"))

ContentType

该解决方案有点混乱,因此最好从正确的格式开始:

    class App extends React.Component {

      constructor(props) {
        super(props);
        this.state = {
          messageContent: 'placeholder'
        }
      }

      setMessage = (data) => {
        this.setState({messageContent : data});
      }

      render() {

        return (
          <div className="App">
            <button id='butt' onClick= {() => this.setMessage('test')} />
            <Notification message = {this.state.messageContent} />
          </div>
        );
      }

    }

    class Notification extends React.Component {

      render () {
        const {message} = this.props;
        return (
          <div id='noti'>
            {message}
          </div>
        )
      }

    }

enter image description here

本文链接:https://www.f2er.com/3104267.html

大家都在问