ggplot2ファセットにラベルを割り当てようとしています。私はこれが文字の問題だと思っているので、私はデータセット内のラベルとまったく同じものを使用していますので、少し時間がかかります。謝ります。エラー:行列の行数が一致する必要があります(ggplotファセット)
set.seed(123)
names <- c("acquisitionsmergers", "analystratings", "assets", "balanceofpayments",
"bankruptcy", "civilunrest", "corporateresponsibility", "credit",
"creditratings", "crime", "dividends", "earnings", "equityactions",
"exploration", "government", "indexes", "industrialaccidents",
"insidertrading", "investorrelations", "laborissues", "legal",
"marketing", "orderimbalances", "partnerships", "pricetargets",
"productsservices", "publicopinion", "regulatory", "revenues",
"security", "stockprices", "taxes", "technicalanalysis", "transportation",
"warconflict")
mylabels <- c("acquisitionsmergers" = "Acquisitions/Mergers",
"analystratings" = "Analyst Ratings",
"assets" = "Assets",
"balanceofpayments" = "Balance of Payments",
"bankruptcy" = "Bankruptcy",
"civilunrest" = "Civil Unrest",
"corporateresponsibility" = "Corporate Responsibility",
"credit" = "Credit",
"creditratings" = "Credit Ratings",
"crime" = "Crime",
"dividends" = "Dividends",
"earnings" = "Earnings",
"equityactions" = "Equity Actions",
"exploration" = "Exploration",
"government" = "Government",
"indexes" = "Indexes",
"industrialaccidents" = "Industrial Accidents",
"insidertrading" = "Insider Trading",
"investorrelations" = "Investor Relations",
"laborissues" = "Labor Issues",
"legal" = "Legal",
"marketing" = "Marketing",
"orderimbalances" = "Order Imbalances",
"partnerships" = "Partnerships",
"pricetargets" = "Price Targets",
"productsservices" = "Product Services",
"publicopinion" = "Public Opinion",
"regulatory" = "Regulatory",
"revenues" = "Revenues",
"security" = "Security",
"stockprices" = "Stockprices",
"taxes" = "Taxes",
"technicalanalysis" = "Technical Analysis",
"transportation" = "Transportation",
"warconflict" = "War Conflict")
df <- data.frame(item = rep(names, each=5), value=rnorm(5*35,5,2), date = rep(seq(as.Date("2000/1/1"), by = "month", length.out = 5),35))
その後、
library(ggplot2)
ggplot(df, aes(x=date, y=value, color=item)) +
geom_line() +
facet_wrap(~ item, ncol=4, scales="free_y", labeller = mylabels)
は
Error in cbind(labels = list(), list(`{`, if (!is.null(.rows) || !is.null(.cols)) { :
number of rows of matrices must match (see arg 2)
を作成し、私は問題なく前ラベラーを使用しましたので、私は、なぜそれがこのエラーを投げていますかわかりません。任意の助け
all(names(mylabels) %in% names)
length(mylabels) == length(names)
ありがとう:私は、このような一致があることを確認することなどいくつかのことを、確認しました!
パーフェクト、感謝すべきプロットする
mylabels
を編集する場合 あなたのアプローチが正常に動作します!いくつかのこと:まず、ラベル要素がユニークな順序として取られていますか?つまり、データフレーム内の元の「アイテム」ベクトルは、ラベルと同じ順序になるようにソートする必要がありますか?第2に、これはバグであるように見えますが、これはggplot2ページでファイルする必要がありますか? – Almacomet@Almacomet 最新の回答を確認してください – aelwan