2017-03-08 1 views
3

各チームのラインがあり、そのラインの色が凡例の色と一致するようにしています。私はそれを行う方法を知っているので、棒グラフであるかのようにプログラムを書いたので、それを線で表現するためにはいくつかの変更が必要です。注:私は一番合った線は望んでいませんが、むしろ点から点につながる線を望んでいます。R MLBチームの複数ライングラフが年ごとに勝利

この次の部分は非常に時間がかかるかもしれないので、私はこれを手伝ってくれるとは思っていませんが、本当にチーム名を置き換えて伝説にチームロゴを付けたいと思っています。伝説では、私はチームと関連した色をボックスではなくラインにしたいと思っています。

これらのいずれかまたは両方のヘルプは非常に高く評価されます。

EDIT:グレーの背景、白いグリッドなど、プログラムの下にあるすべての機能を維持したいと考えています。

df <- read.table(textConnection(
    'Year Orioles RedSox Yankees Rays BlueJays 
    1998 79  92  114 63 88 
    1999 78  94  98  69 84 
    2000 74  85  87  69 83 
    2001 63  82  95  62 80 
    2002 67  93  103 55 78 
    2003 71  95  101 63 86 
    2004 78  98  101 70 67 
    2005 74  95  95  67 80 
    2006 70  86  97  61 87 
    2007 69  96  94  66 83 
    2008 68  95  89  97 86 
    2009 64  95  103 84 75 
    2010 66  89  95  96 85 
    2011 69  90  97  91 81 
    2012 93  69  95  90 73 
    2013 85  97  85  92 74 
    2014 96  71  84  77 83 
    2015 81  78  87  80 93 
    2016 89  93  84  68 89'), header = TRUE) 



df %>% 
    gather(Team, Wins, -Year) %>% 
    mutate(Team = factor(Team, c("Orioles", "RedSox", "Yankees","Rays","BlueJays"))) %>% 
    ggplot(aes(x=Year, y=Wins)) + 
    ggtitle("AL East Wins") + 
    ylab("Wins") + 
    geom_col(aes(fill = Team), position = "dodge") + 
    scale_fill_manual(values = c("orange", "red", "blue", "black","purple"))+ 
    theme(
    plot.title = element_text(hjust=0.5), 
    axis.title.y = element_text(angle = 0, vjust = 0.5), 
    panel.background = element_rect(fill = "gray"), 
    panel.grid = element_line(colour = "white") 
) 

答えて

4

あなたはこのようなあなたの基本的な目標を達成するために代わりgeom_col(aes(fill = Team)geom_path(aes(color = Team))と名付けられたカラーパレットを使用することができます。あなたの答えのための

# break this off the pipeline 
df <- gather(df, Team, Wins, -Year) %>% 
    mutate(Team = factor(Team, c("Orioles", "RedSox", "Yankees","Rays","BlueJays"))) 

# if you want to resuse the same theme a bunch this is nice 
# theme_grey() is the default theme 
theme_set(theme_grey() + 
       theme(plot.title = element_text(hjust=0.5), 
        axis.title.y = element_text(angle = 0, vjust = 0.5), 
        panel.background = element_rect(fill = "gray"))) 

# named palettes are easy 
# for specific colors i like hex codes the best 
# i just grabbed these of this nice website TeamColorCodes, could be fun! 
cust <- c("#FC4C00", "#C60C30", "#1C2841", "#79BDEE","#003DA5") 
names(cust) <- levels(df$Team) 

# use geom_path inplace of geom_col 
ggplot(df, aes(x=Year, y=Wins, color = Team)) + 
    geom_path(aes(color = Team)) + 
    scale_color_manual(values = cust) + 
    labs(title = "AL East Wins", 
     subtitle = "Ahhh", 
     y = "Wins", 
     x = "Year") 

Link to teamcolorcodes.com

enter image description here

+0

感謝。また、どのようにライトブルーを作ることができますか?私は "青"から青(.3)に変更しようとしましたが、エラーが発生しました –

+0

また、すべてが素晴らしいように見えますが、私が望む唯一の他のものはグリッドラインです。 –

+0

私は間違いなくそのウェブサイトの色を確認するつもりです、ありがとう。 –

関連する問題