2017-09-22 3 views
0

におけるエラーバーで可能な問題(謝罪 - それはBIGです):エラーで(空の(データ))場合 - サンプルデータについてはggplot2

df<-structure(list(SITCD = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("46 - SIS", 
"51 - NFH", "54 - PAA"), class = "factor"), SITCD1 = structure(c(3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L), .Label = c("NFH", "PAA", "SIS"), class = "factor"), 
    Code = structure(c(10L, 14L, 8L, 6L, 9L, 7L, 1L, 1L, 13L, 
    13L, 13L, 5L, 19L, 4L, 20L, 21L, 22L, 3L, 2L, 1L, 1L, 11L, 
    11L, 11L, 18L, 23L, 15L, 16L, 23L, 17L, 1L, 1L, 12L, 12L, 
    12L, 12L, 12L, 12L), .Label = c("Dummy", "I-8596", "K-1036", 
    "K-2295", "K-2749", "KIA-35509 KIA-35510 LuS-8460", "KIA-35512 LuS-8461", 
    "LuS-8459", "LuS-8462", "LuS-8783", "NFHHuy3", "PAAHuy3", 
    "SisHuy3", "SUERC-15780", "SUERC-34115", "SUERC-34116", "SUERC-34117", 
    "SUERC-34122", "SUERC-45707", "SUERC-45708", "UCIAMS-133556/UCIAMS-133557", 
    "UCIAMS-133559/UCIAMS-133560", "Unknown"), class = "factor"), 
    Dated = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 2L, 2L, 
    2L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 3L, 3L, 2L, 2L, 2L, 1L, 
    1L, 1L, 1L, 1L, 1L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("G", 
    "HUY3", "Marine Limit", "SHF"), class = "factor"), Type = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L, 5L, 5L, 4L, 4L, 4L, 1L, 1L, 2L, 2L, 2L, 
    2L, 3L, 3L, 5L, 5L, 4L, 4L, 4L, 1L, 1L, 2L, 2L, 2L, 3L, 5L, 
    5L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Above", "At", "Below", 
    "HUY3", "Marine Limit"), class = "factor"), RSL = c(18.4, 
    13, 39.8, 98.4, 129.9, 94.9, 138, 142, 0, 0, 0, 120, 138.69, 
    55.1, 50.55, 29.22, 93.18, 40, 16, 118, 123, 79.38, -7.33, 
    0, 52, 52, 0.4, -0.95, 15.22, -1.14, 51.7, 53.4, 1.18, 3.97, 
    6.95, 11.01, 10.65, 18.3), RSL_error = c(0.5, 0.075, 0.5, 
    0.5, 0.5, 0.5, 0, 0, 0, 0, 0, 2, 2, 2, 0.1, 0.26, 0.1, 5, 
    2, 0, 0, 0, 0, 0, 1.5, 1.5, 0.175285481, 0.146714008, 2, 
    0.15, 0, 0, 0, 0, 0, 0, 0, 0), Age = c(5075.5, 5741.5, 8430.5, 
    9784, 10095, 10366, 10095, 10095, 14000, 4000, 3000, 9837, 
    8461.5, 8216.5, 8761, 7463, 10050.5, 8281, 7437.5, 10536, 
    10536, 14000, 1000, 0, 10353.5, 10938, 9478, 9364.5, 9861, 
    2253, 11001, 11001, 14000, 13500, 13000, 12000, 11500, 11000 
    ), age_error = c(207.5, 135.5, 107.5, 384.5, 176, 124, 0, 
    0, 0, 0, 0, 403, 75.5, 185.5, 209, 33, 127.5, 337, 217.5, 
    0, 0, 0, 0, 0, 123.5, 269, 54, 104.5, 300, 96, 0, 0, 0, 0, 
    0, 0, 0, 0), x_min_error = c(4868, 5606, 8323, 9399.5, 9919, 
    10242, 0, 0, 0, 0, 0, 9434, 8386, 8031, 8552, 7430, 9923, 
    7944, 7220, 0, 0, 0, 0, 0, 10230, 10669, 9424, 9260, 9561, 
    2157, 0, 0, 0, 0, 0, 0, 0, 0), x_max_error = c(5283, 5877, 
    8538, 10168.5, 10271, 10490, 0, 0, 0, 0, 0, 10240, 8537, 
    8402, 8970, 7496, 10178, 8618, 7655, 0, 0, 0, 0, 0, 10477, 
    11207, 9532, 9469, 10161, 2349, 0, 0, 0, 0, 0, 0, 0, 0), 
    y_min_error = c(17.9, 12.925, 39.3, 97.9, 129.4, 94.4, 0, 
    0, 0, 0, 0, 118, 136.69, 53.1, 50.45, 28.96, 93.08, 35, 14, 
    0, 0, 0, 0, 0, 50.5, 50.5, 0.224714519, -1.096714008, 13.22, 
    -1.29, 0, 0, 0, 0, 0, 0, 0, 0), y_max_error = c(18.9, 13.075, 
    40.3, 98.9, 130.4, 95.4, 0, 0, 0, 0, 0, 122, 140.69, 57.1, 
    50.65, 29.48, 93.28, 45, 18, 0, 0, 0, 0, 0, 53.5, 53.5, 0.575285481, 
    -0.803285992, 17.22, -0.99, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("SITCD", 
"SITCD1", "Code", "Dated", "Type", "RSL", "RSL_error", "Age", 
"age_error", "x_min_error", "x_max_error", "y_min_error", "y_max_error" 
), class = "data.frame", row.names = c(NA, -38L)) 

私は、コードを使用して一連のグラフを生成したいです:私は、エラーメッセージを取得しかし

g <- ggplot() + 
    geom_point(data = df, aes(x=Age, y=RSL, colour=Type), size=0, alpha = 0)+ 
    geom_point(data = df[df$Type!="HUY3",], aes(x=Age, y=RSL, colour = Type), size=1.5) + 
    geom_line(data = df[df$Type=="HUY3",], aes(x=Age, y=RSL), size=0.7, color="black")+ 
    scale_colour_manual(values=c("red", "black", "blue","grey","yellow"))+ 
    geom_errorbar(aes(ymin=y_min_error, ymax=y_max_error,width=0)) + # y error bar 
    geom_errorbarh(aes(xmin=x_min_error, xmax=x_max_error,height=0)) + 
    ylab("RSL (m)") + 
    xlab("Age cal yr. BP")+ 
    theme_bw()+ #Black outline around the graph 
    scale_x_reverse(limits=c(15000,0), breaks=c(14000,12000,10000,8000,6000,4000,2000,0),expand=c(0,-10))+ 
    scale_shape_manual(values=c(19,19,19,19,19))+ # sets shape of points 
    scale_y_continuous(breaks=seq(-10,150,10))+ # sets y axis tick points, from -10 to 130, by 10 
    expand_limits(y=-10)+ # sets y axis zero 
    theme(legend.position="bottom") + 
    #theme_classic() + 
    theme(axis.line=element_line(colour = "black", size = 0.5, linetype = "solid")) + # adds solid black x and y axis 
    facet_wrap(~SITCD, ncol=2) 

g 

Error in if (empty(data)) { : missing value where TRUE/FALSE needed 

を私はこれは非常に喜んで実行したエラーバー(とは何かを持っていると思いますコードの他の行)、私は何をすべきか考えることができません。他のstackoverflowの答えは適用されないようです。誰でも助けてくれますか?

UPDATE:コメントを使用して、私は次のことを実行しようが、私は今のエラーを取得:

Error: unexpected symbol in: 
" facet_wrap(~SITCD, ncol=2) 

どれ更なるアイデア(エラーがいずれかの作業をしている理由を私は知りません)。

g <- ggplot() + 
    geom_point(data = df, aes(x=Age, y=RSL, colour=Type), size=0, alpha = 0)+ 
    geom_point(data = df[df$Type!="HUY3",], aes(x=Age, y=RSL, colour = Type), size=1.5) + 
    geom_line(data = df[df$Type=="HUY3",], aes(x=Age, y=RSL), size=0.7, color="black")+ 
    scale_colour_manual(values=c("red", "black", "blue","grey","yellow"))+ 
    geom_errorbar(data = df, aes(x = Age, ymin=y_min_error, ymax=y_max_error)+ 
    geom_errorbarh(data = df, aes(x = Age, xmin=x_min_error, xmax=x_max_error,height=0)) + 
    ylab("RSL (m)") + 
    xlab("Age cal yr. BP")+ 
    theme_bw()+ #Black outline around the graph 
    scale_x_reverse(limits=c(15000,0), breaks=c(14000,12000,10000,8000,6000,4000,2000,0),expand=c(0,-10))+ 
    scale_shape_manual(values=c(19,19,19,19,19))+ # sets shape of points 
    scale_y_continuous(breaks=seq(-10,150,10))+ # sets y axis tick points, from -10 to 130, by 10 
    expand_limits(y=-10)+ # sets y axis zero 
    theme(legend.position="bottom") + 
    #theme_classic() + 
    theme(axis.line=element_line(colour = "black", size = 0.5, linetype = "solid")) + # adds solid black x and y axis 
    facet_wrap(~SITCD, ncol=2) 
g 

答えて

0

エラーバーgeomsにデータセットを指定しないでください。たとえば、実際にgeom_errorbar(data = df, aes(x = Age, ymin=y_min_error, ymax=y_max_error))を意味しますか?

+0

ありがとう@Lyngbakr、しかしそれは動作しません。今、エラーメッセージeval(代替(リスト(...))、 '_data'、parent.frame())のエラーメッセージが表示されます: オブジェクト 'x'は見つかりませんでした。 –

+0

あなたは 'aes'の' x'も見逃しました。私は私の答えを更新しました。 – Lyngbakr

+0

'width = 0'は' aes'の外になければなりませんが、エラーバーも隠すでしょう。 – Axeman

関連する問題