2017-08-24 11 views
1

0記号が表示されている2点の折れ線グラフにX記号を入れたいと思います。ggplot:折れ線グラフ内の特定の点にX記号を作成する

data <- read.table(text = " 
Clients Throughput Systems ErrorBar 
250 2494 Za  72.986 
500 2491 Za  104.854 
750 401 Za  130.034 
1000 0 Za  0 
1250 0 Za  0 
250 2501 ZCT 58.987 
500 2499 ZCT 89.927 
750 2380 ZCT 130.475 
1000 2321 ZCT 139.450 
1250 2296 ZCT 142.580", header = TRUE) 

次のように折れ線グラフを描画するためのスクリプト:

plot1 <- ggplot(data=data , aes(x=Clients, y=Throughput, group=Systems, colour = Systems, shape=Systems)) + 
    geom_errorbar(aes(ymin=Throughput-Error, ymax=Throughput+Error), width=20.5, colour="black") + 
    geom_line(size=1.2) + 
    geom_point(size=2.3) 

plot1 <- plot1 + scale_y_continuous(breaks= seq(0,3000,500), limits = c(0,3000)) + 
    labs(x="Number of clients") + 
    scale_x_continuous(breaks = c(250,500,750,1000,1250)) + 
    labs(y="Throughput (abds/sec)") 

plot1 <- plot1 + scale_colour_manual(values=c("#00ff00","#0000ff")) 

plot1 <- plot1 + theme_bw() + 
    theme(legend.position="bottom") + 
    labs(fill="", colour=" ", shape=" ") + 
    theme(text = element_text(size=18)) + 
    guides(fill = guide_legend(keywidth = 0.8, keyheight = 0.01)) 

plot1 

任意の助けを

私は、次のようなデータを持っていますか?

答えて

1

あなたはannotateを使用してXシンボルを追加することができます。

data <- read.table(text = " 
Clients Throughput Systems Error 
250 2494 Za  72.986 
500 2491 Za  104.854 
750 401 Za  130.034 
1000 0 Za  0 
1250 0 Za  0 
250 2501 ZCT 58.987 
500 2499 ZCT 89.927 
750 2380 ZCT 130.475 
1000 2321 ZCT 139.450 
1250 2296 ZCT 142.580", header = TRUE) 

plot1 <- ggplot(data=data , aes(x=Clients, y=Throughput, group=Systems, colour = Systems, shape=Systems)) + 
    geom_errorbar(aes(ymin=Throughput-Error, ymax=Throughput+Error), width=20.5, colour="black") + 
    geom_line(size=1.2) + 
    geom_point(size=2.3) 

plot1 <- plot1 + scale_y_continuous(breaks= seq(0,3000,500), limits = c(0,3000)) + 
    labs(x="Number of clients") + 
    scale_x_continuous(breaks = c(250,500,750,1000,1250)) + 
    labs(y="Throughput (abds/sec)") 

plot1 <- plot1 + scale_colour_manual(values=c("#00ff00","#0000ff")) 

plot1 <- plot1 + theme_bw() + 
    theme(legend.position="bottom") + 
    labs(fill="", colour=" ", shape=" ") + 
    theme(text = element_text(size=18)) + 
    guides(fill = guide_legend(keywidth = 0.8, keyheight = 0.01))+ 
    annotate("Text", x=data$Clients[data$Throughput==0], 
        y=data$Throughput[data$Throughput==0], label="X", size=6) 

plot1 

enter image description here

+0

はい、それは私が探していたものです。本当にありがとうございます@マルコサンドリ –

+0

私は750、1000、1250で0がある場合、それは1000と1250でXのシンボルを表示するだけで、別の問題が発生しました。どのように同様に750データポイントでXを追加するには? –

+0

ありがとう@マルコサンドリ、それは動作します。 –

関連する問題