2017-05-31 1 views
0

RをプロットしてStateを使ってこのグラフをグループ化するにはどうすればよいですか?別の列を棒グラフでグループ化する(R)

データ:Excelで作ら

State <- c("Tennessee", "Tennessee", "Tennessee", "Tennessee", 
      "Kentucky", "Kentucky", "Kentucky", "Kentucky", "Kentucky", 
      "Georgia", "Georgia", "Georgia"), 

    City <- c("Chattanooga", "Knoxville", "Memphis", "Nashville", 
      "Covington", "Owensboro", "Bowling Green", "Lexington", "Louisville", 
      "Columbus City", "Augusta", "Atlanta City"), 

    Population <- c(177571, 186239, 652717, 660388, 
       40640, 57265, 58067, 295803, 597337, 
       189885, 195844, 420033) 

サンプルチャート:ggplotClick here for image

plot_ly() %>% 
     add_trace(
     x = ~City, 
     y = ~Population, 
     type = 'bar', 
     name = 'Population') 

答えて

0

data <- data.frame(State, City, Population) 
colnames(data)<-c("category","subcategory","population") 

ggplot(data, aes(category, population)) + 
    geom_bar(aes(fill = category, color=subcategory), position = "dodge", stat="identity")+ 
    theme_minimal() + 
    scale_color_manual(values=c(rep("white", 17))) + 
    theme(legend.position="none") 

​​

と、ggplotlyを使用して:

ggplotly() 

enter image description here

+0

はggplotを使用するか、またはggplotlyせずにこれを行う方法はありますか?これは他のチャートがたくさんあるshinyappにあり、プロットしたばかりの他のチャートと同じデザインを使用できるようにする必要があります。また、間隔を固定する方法はありますか? – Xenedra

関連する問題