2016-09-30 18 views
0

私は両方を検索しました。これのために& Google。多くの回答がありますが、実際の問題を解決するのに役立つものを見つけることはできません。私はです。オブジェクトが見つかりません。エラー

は、ここに私のコードです:

library(RNeo4j) 
    library(tidyverse) 
    library(stringr) 
    library(MASS) 

### uncomment the next 2 lines to reconnect to server & re-query the database 
# setwd("~/Desktop/Dashrock/Neo4j") 
# source("N4j_connect_query.R") 

df <- naics_jll %>% 
    group_by(m.mkt,c1.name) %>% 
    summarize(n1_4_pct =sum(n.n1_4)/sum(n.est), 
       n5_9_pct =sum(n.n5_9)/sum(n.est), 
       n10_19_pct =sum(n.n10_19)/sum(n.est), 
       n20_49_pct =sum(n.n20_49)/sum(n.est), 
       n50_99_pct =sum(n.n50_99)/sum(n.est), 
       n100_249_pct =sum(n.n100_249)/sum(n.est), 
       n250_499_pct =sum(n.n250_499)/sum(n.est), 
       n500_999_pct =sum(n.n500_999)/sum(n.est), 
       n1000_pct =sum(n.n1000)/sum(n.est), 
       n1000_1_pct =sum(n.n1000_1)/sum(n.est), 
       n1000_2_pct =sum(n.n1000_2)/sum(n.est), 
       n1000_3_pct =sum(n.n1000_3)/sum(n.est), 
       n1000_4_pct =sum(n.n1000_4)/sum(n.est), 
       ap = sum(n.ap), 
       emp = sum(n.emp), 
       num_firms = sum(n.est)) 

g <- ggplot(df) 

    g + 
    geom_point(aes(x=c1.name, y=n100_249_pct, color = factor(m.mkt)), na.rm = TRUE) + 
    facet_grid(. ~ m.mkt) + 
    labs(x = "Industry Code (NAICS)", y = "Btwn 100-249 Employees (as % of All Companies)", title = "Company Profiles") + 
    theme(axis.text.x = element_text(angle=90, hjust = .5, vjust=.5, size=5)) 

これだけで正常に動作します。出力は次のとおりです。

ggplot output

問題は、私は(私が本当に欲しいものです)geom_pointからgeom_barに変更したときに、私はこのエラーの異なるバージョンを取得するには、次のとおりです。

Error in factor(n100_249_pct) : object 'n100_249_pct' not found

何が悪いです?

+1

[再現可能な例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)を提供するデータやコードを含めることができますか? )?また...ちょうど推測... 'geom_bar(stat =" identity ")' ...を試してみましたか? –

+0

ありがとうございます! stat = "identity"固定しました。 – Steve

答えて

1

stat = "identity"をパラメータとして使用して、geom_bar()ベンの提案に従ってください。

編集(2017年1月29日)ggplotのバージョン2.2.0は、geom_bar(stat = "identity")のために短い手で新しい機能geom_col()を持っています。

+0

これは、この回答を「use geom_bar(stat = "identity") ''」に減らすのに役立つかもしれません。読みやすく、そうでなければ見逃すことはありません。 .. –

関連する問題