1

私はここでは新しいですが、あなたが私を助けてくれることを願っています。私は自分の問題をグーグルで検索しましたが、解決できませんでした。

Rでggplotを使用してプロットしたいデータがたくさん含まれているデータフレームがあります。すべてが非常にうまく機能しますが、凡例は私を夢中にさせます。凡例の線種は、私が定義したものではなく、常に塗りつぶされています。

csvファイルを読み込んでから、ループを使用してサブセットを作成し、SummarySE()を使用してサブセットを要約します。

サブセットは次のようになります。

    ExperimentCombinations   LB TargetPosition  N C_measured         sd          se         ci
1                     HS 0.10         Foveal 10 0.11007970 0.04114193 0.013010221 0.02943116
2                     HS 0.21         Foveal 10 0.09821870 0.04838134 0.015299523 0.03460992
3                     HS 0.30         Foveal  9 0.07911856 0.04037776 0.013459252 0.03103709
4                     HS 1.00         Foveal 11 0.06657355 0.02688821 0.008107099 0.01806374
5                    LED 0.10         Foveal  8 0.12569725 0.03607487 0.012754393 0.03015935
6                    LED 0.21         Foveal 10 0.08797370 0.02091996 0.006615472 0.01496524
7                    LED 0.30         Foveal 10 0.07358290 0.03002596 0.009495042 0.02147928
8                    LED 1.00         Foveal  8 0.06630350 0.01894423 0.006697796 0.01583777

この場合、TargetPositionのレベルは中心窩または周辺です。私が使用しているggplotコードは次のとおりです(問題を解決しようとしていたため、ひどいように見えます...):

    ColourFoveal <- c("#FFCC33","#00CCFF")
        ColourPeripheral <- c("#FFCC33","#00CCFF")
        #ColourPeripheral <- c("#FF9900","#0066FF")
        PointType <- c(20,20)
        PointTypeSweepUp <- c(24,24)
        PointTypeSweepDown <- c(25,25)
        ColourHSFillFoveal <- c("#FFCC33", "#FFCC33")
        ColourHSFillPeripheral <- c("#FF9900", "#FF9900")
        #LineTypeFoveal <- c("solid", "solid")
        LineTypePeripheral <- c("dashed","dashed")
        xbreaks <- c(0.1,0.21,0.3,1.0)
        plotsYmax <- 0.2 



    if(field=="Peripheral"){
                        lineType<-sprintf("dashed")
                        lineColour<-ColourPeripheral
                    }else{
                        lineType<-"solid"
                        lineColour<-ColourFoveal
                    }
                    ggplot(df, aes(x=LB, y=C_measured, shape=ExperimentCombinations, colour=ExperimentCombinations)) +
                        geom_errorbar(aes(ymin=C_measured-se, ymax=C_measured+se), width=.1) +
                        geom_line(linetype=lineType) +
                        geom_point() +

                        ggtitle(paste(targetDataFrame$AgeGroup, targetDataFrame$TargetPosition)) +
                        scale_colour_manual(name="", values=lineColour)+
                        scale_shape_manual(name="", values=PointType)+
                        scale_fill_manual(name="", values=lineColour)+                  
                        scale_x_continuous(breaks=xbreaks)+
                        coord_cartesian(ylim = c(0, plotsYmax+0.01))+
                        scale_y_continuous(breaks=c(0,0.05,0.1,0.15,0.2))+                  
                        theme(axis.line=element_line(colour="black"))+                  
                        theme(panel.grid=element_blank())+
                        theme_bw()+
                        theme(legend.key.width=unit(2,"line"))
}

周辺のプロットには破線、中心窩のプロットには実線が必要です。私が得るものはいつもこのようなものです:(新しいユーザーとして私は画像を投稿することを許可されていません!)線は私が好きな色で破線で示され、ポイントも正しいです。しかし、凡例では、線は破線ではなく実線で示されています。凡例でも色とポイントは大丈夫です。

周辺の場合に破線で示されている凡例の線種を定義するのを手伝ってもらえますか?

4

0 に答える 0