2017-12-07 1 views
-1
내가 ggplot2의 막대 그래프를 만들려고 해요

, 나는 열 이름과 관련된 숫자 값을 가진 dataframe를 가지고,하지만 난 dataframe 만드는 예기치 않은 오류로 계속 실행 :만들기 막대 그래프의 ggplot2 하나의 희미한 dataframe

ggplot(audit_count,aes(x=colnames(audit_count),y=audit_count[1,])) +geom_bar() 

날 오류 메시지

Error: Aesthetics must be either length 1 or the same as the data (1): x, y 

을 제공하지만,이 에러 메시지는 COLNAMES (audit_count)로서, 저 이해와 [1, 상기와 동일한 길이이다 audit_count 그다지.

bar 이름으로 열 이름과 y 값으로 숫자 값으로 barchart로 플롯하기 위해 데이터를 변환해야하는 일종의 변환이 있습니까?

데이터 아래 :

structure(list(page_title_missing = 56L, page_title_length = 164L, 
    page_title_duplicates = 630L, meta_desc_missing = 703L, meta_desc_length = 0L, 
    meta_desc_duplicate = 28L, url_dynamic = 397L, url_underscore = 26L, 
    url_uppercase = 701L, pagination = 0L, image_alt_missing = 223L, 
    h1_missing = 56L, h1_multiple = 427L, meta_keyword_present = 0L, 
    https_missing = 0L, non_canonical = 293L, meta_no_index = 0L, 
    meta_no_follow = 0L, content_duplication = 617L, content_depth = 461L, 
    non_301_redirects = 55L, redirec_chains = 56L, errors_404 = 0L, 
    mobile_url_inconsisten = 0L, hreflang_missing = 731L), .Names = c("page_title_missing", 
"page_title_length", "page_title_duplicates", "meta_desc_missing", 
"meta_desc_length", "meta_desc_duplicate", "url_dynamic", "url_underscore", 
"url_uppercase", "pagination", "image_alt_missing", "h1_missing", 
"h1_multiple", "meta_keyword_present", "https_missing", "non_canonical", 
"meta_no_index", "meta_no_follow", "content_duplication", "content_depth", 
"non_301_redirects", "redirec_chains", "errors_404", "mobile_url_inconsisten", 
"hreflang_missing"), row.names = c(NA, -1L), class = "data.frame") 

답변

0

ggplot 데이터가 규칙적인 형태로하고 aes()는 그래픽 속성에 data.frame의 열을 매핑해야 기대하는 바 길이로 한 값을 사용하여 의미한다. 실제로 데이터를 에이스로 직접 전달하지는 않습니다. 한 빠른 수정은 데이터가 ggplot 그것을 받아들이 긴 형식으로해야합니까,

ggplot(tidyr::gather(audit_count, variable, value)) + 
    geom_bar(aes(x=variable,y=value), stat="identity") + 
    coord_flip() 

또는 도움을

ggplot(reshape2::melt(audit_count)) + 
    geom_bar(aes(x=variable,y=value), stat="identity") + 
    coord_flip() 
+0

감사합니다. 그런 식으로 ggplot2가 예상 한 데이터를 인식하지 못했습니다. – user12978541243

0

제가 t()으로 데이터 트랜스 것이다하고 ggplot에 Y로하여 X와 같은 rownames()V1에서 공급. geom_bar()에서 stat = 'identity'

library(ggplot2) 
library(dplyr) 

audit_count <- t(audit_count) %>% as.data.frame 
ggplot(audit_count, aes(x = rownames(audit_count), y = V1)) + geom_bar(stat = 'identity') + coord_flip() 
+0

감사입니까? – user12978541243

+0

그래, 꽤 많이. – BigTimeStats

관련 문제