我正在尝试使用ggplot2创建堆积面积图。 到目前为止,它仍然有效,但是现在我在更改该区域的颜色时遇到了问题。 我的情节看起来像:
但是我希望它从绿色变成红色(中间应该是黄色)。我该如何更改?
ggplot(df.f, aes(x=Year,y=Population,fill=AgeClass)) +
geom_area()
编辑: 它看起来应该像这样:
这是dput(df)的输出:
structure(list(AgeClass = structure(c(1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L
), .Label = c("0-4", "5-9", "10-14", "15-19", "20-24", "25-29",
"30-34", "35-39", "40-44", "45-49", "50-54", "55-59", "60-64",
"65-69", "70-74", "75-79", "80+"), class = "factor"), Year = c(1960L,
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L,
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L,
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1962L, 1962L, 1962L,
1962L, 1962L, 1962L, 1962L, 1962L, 1962L, 1962L, 1962L, 1962L,
1962L, 1962L, 1962L, 1962L, 1962L, 1963L, 1963L, 1963L, 1963L,
1963L, 1963L, 1963L, 1963L, 1963L, 1963L, 1963L, 1963L, 1963L,
1963L, 1963L, 1963L, 1963L, 1964L, 1964L, 1964L, 1964L, 1964L,
1964L, 1964L, 1964L, 1964L, 1964L, 1964L, 1964L, 1964L, 1964L,
1964L, 1964L, 1964L, 1965L, 1965L, 1965L, 1965L, 1965L, 1965L,
1965L, 1965L, 1965L, 1965L, 1965L, 1965L, 1965L, 1965L, 1965L,
1965L, 1965L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L,
1966L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L,
1966L, 1967L, 1967L, 1967L, 1967L, 1967L, 1967L, 1967L, 1967L,
1967L, 1967L, 1967L, 1967L, 1967L, 1967L, 1967L, 1967L, 1967L,
1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1968L,
1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1968L, 1969L,
1969L, 1969L, 1969L, 1969L, 1969L, 1969L, 1969L, 1969L, 1969L,
1969L, 1969L, 1969L, 1969L, 1969L, 1969L, 1969L, 1970L, 1970L,
1970L, 1970L, 1970L, 1970L, 1970L, 1970L, 1970L, 1970L, 1970L,
1970L, 1970L, 1970L, 1970L, 1970L, 1970L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1974L, 1974L, 1974L, 1974L, 1974L, 1974L,
1974L, 1974L, 1974L, 1974L, 1974L, 1974L, 1974L, 1974L, 1974L,
1974L, 1974L, 1975L, 1975L, 1975L, 1975L, 1975L, 1975L, 1975L,
1975L, 1975L, 1975L, 1975L, 1975L, 1975L, 1975L, 1975L, 1975L,
1975L, 1976L, 1976L, 1976L, 1976L, 1976L, 1976L, 1976L, 1976L,
1976L, 1976L, 1976L, 1976L, 1976L, 1976L, 1976L, 1976L, 1976L,
1977L, 1977L, 1977L, 1977L, 1977L, 1977L, 1977L, 1977L, 1977L,
1977L, 1977L, 1977L, 1977L, 1977L, 1977L, 1977L, 1977L, 1978L,
1978L, 1978L, 1978L, 1978L, 1978L, 1978L, 1978L, 1978L, 1978L,
1978L, 1978L, 1978L, 1978L, 1978L, 1978L, 1978L, 1979L, 1979L,
1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L,
1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1980L, 1980L, 1980L,
1980L, 1980L, 1980L, 1980L, 1980L, 1980L, 1980L, 1980L, 1980L,
1980L, 1980L, 1980L, 1980L, 1980L, 1981L, 1981L, 1981L, 1981L,
1981L, 1981L, 1981L, 1981L, 1981L, 1981L, 1981L, 1981L, 1981L,
1981L, 1981L, 1981L, 1981L, 1982L, 1982L, 1982L, 1982L, 1982L,
1982L, 1982L, 1982L, 1982L, 1982L, 1982L, 1982L, 1982L, 1982L,
1982L, 1982L, 1982L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L,
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L,
1984L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L,
1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L,
1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1986L,
1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1987L,
1987L, 1987L, 1987L, 1987L, 1987L, 1987L, 1987L, 1987L, 1987L,
1987L, 1987L, 1987L, 1987L, 1987L, 1987L, 1987L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1988L,
1988L, 1988L, 1988L, 1988L, 1988L, 1988L, 1989L, 1989L, 1989L,
1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L, 1989L,
1989L, 1989L, 1989L, 1989L, 1989L, 1990L, 1990L, 1990L, 1990L,
1990L, 1990L, 1990L, 1990L, 1990L, 1990L, 1990L, 1990L, 1990L,
1990L, 1990L, 1990L, 1990L, 1991L, 1991L, 1991L, 1991L, 1991L,
1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L,
1991L, 1991L, 1991L, 1992L, 1992L, 1992L, 1992L, 1992L, 1992L,
1992L, 1992L, 1992L, 1992L, 1992L, 1992L, 1992L, 1992L, 1992L,
1992L, 1992L, 1993L, 1993L, 1993L, 1993L, 1993L, 1993L, 1993L,
1993L, 1993L, 1993L, 1993L, 1993L, 1993L, 1993L, 1993L, 1993L,
1993L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L,
1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L,
1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L,
1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1996L,
1996L, 1996L, 1996L, 1996L, 1996L, 1996L, 1996L, 1996L, 1996L,
1996L, 1996L, 1996L, 1996L, 1996L, 1996L, 1996L, 1997L, 1997L,
1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L,
1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1998L, 1998L, 1998L,
1998L, 1998L, 1998L, 1998L, 1998L, 1998L, 1998L, 1998L, 1998L,
1998L, 1998L, 1998L, 1998L, 1998L, 1999L, 1999L, 1999L, 1999L,
1999L, 1999L, 1999L, 1999L, 1999L, 1999L, 1999L, 1999L, 1999L,
1999L, 1999L, 1999L, 1999L, 2000L, 2000L, 2000L, 2000L, 2000L,
2000L, 2000L, 2000L, 2000L, 2000L, 2000L, 2000L, 2000L, 2000L,
2000L, 2000L, 2000L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L,
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L,
2001L, 2001L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L,
2002L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L,
2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L,
2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L,
2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2005L,
2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L,
2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2006L, 2006L,
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L,
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L,
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2014L,
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L,
2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2014L, 2015L, 2015L,
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2015L,
2015L, 2015L, 2015L, 2015L, 2015L, 2015L, 2016L, 2016L, 2016L,
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L,
2016L, 2016L, 2016L, 2016L, 2016L, 2017L, 2017L, 2017L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L,
2017L, 2017L, 2017L, 2017L), Population = c(2942.156, 2682.154,
2362.663, 2611.033, 3130.976, 2535.051, 2331.261, 1944.9, 1403.342,
2106.763, 2358.97, 2315.054, 1776.815, 1270.862, 980.556, 640.969,
470.355, 2965.041, 2759.563, 2402.221, 2535.326, 3123.585, 2663.221,
2391.102, 2064.567, 1418.236, 1959.117, 2316.832, 2326.657, 1841.806,
1298.332, 976.367, 648.334, 500.123, 3032.574, 2821.527, 2468.26,
2479.469, 3048.779, 2832.693, 2430.82, 2171.129, 1517.558, 1774.122,
2281.118, 2319.365, 1915.533, 1336.677, 968.829, 656.546, 519.611,
3125.542, 2866.621, 2552.172, 2444.445, 2931.459, 3011.155, 2464.739,
2264.799, 1674.035, 1584.998, 2238.667, 2298.742, 1990.334, 1383.813,
963.929, 664.094, 527.964, 3205.623, 2900.206, 2634.589, 2428.146,
2809.918, 3144.293, 2516.885, 2346.798, 1839.011, 1444.164, 2167.168,
2271.694, 2052.679, 1437.382, 968.233, 667.713, 524.526, 3255.446,
2943.143, 2705.921, 2435.354, 2715.385, 3207.396, 2607.941, 2422.867,
1985.123, 1388.356, 2061.028, 2247.001, 2099.377, 1500.077, 986.943,
668.106, 510.213, 3317.555, 3008.082, 2763.403, 2464.573, 2646.091,
3209.975, 2724.888, 2468.295, 2106.194, 1403.594, 1909.567, 2205.756,
2109.884, 1555.956, 1006.313, 665.365, 538.053, 3317.105, 3073.223,
2804.969, 2510.333, 2581.206, 3140.182, 2880.303, 2481.5, 2204.691,
1499.616, 1714.762, 2163.317, 2097.218, 1615, 1028.291, 655.49,
554.738, 3271.8, 3145.436, 2845.603, 2571.657, 2531.209, 3032.695,
3052.749, 2489.367, 2287.274, 1652.941, 1518.483, 2115.24, 2074.983,
1675.574, 1056.508, 646.453, 559.094, 3204.092, 3225.402, 2904.965,
2643.376, 2507.047, 2934.448, 3202.569, 2531.669, 2365.253, 1822.035,
1379.861, 2049.229, 2058.266, 1733.605, 1096.292, 646.285, 550.312,
3095.626, 3271.497, 2966.577, 2697.278, 2491.464, 2843.332, 3273.269,
2607.628, 2422.212, 1961.458, 1321.003, 1939.414, 2033.794, 1770.125,
1140.299, 652.157, 523.213, 2960.512, 3295.47, 3040.864, 2759.914,
2501.497, 2744.102, 3265.292, 2719.062, 2453.033, 2073.755, 1339.054,
1787.301, 1992.84, 1777.075, 1185.222, 668.082, 543.968, 2793.676,
3308.865, 3131.112, 2828.598, 2553.94, 2669.992, 3205.661, 2888.735,
2470.462, 2177.977, 1445.561, 1607.549, 1965.707, 1778.274, 1240.495,
686.683, 555.98, 2604.373, 3292.521, 3216.619, 2893.165, 2626.08,
2612.8, 3099.744, 3070.029, 2481.835, 2263.918, 1604.096, 1425.547,
1930.454, 1770.169, 1294.283, 706.122, 556.732, 2423.818, 3240.934,
3281.705, 2955.211, 2697.06, 2572.941, 2979.029, 3203.943, 2513.546,
2329.814, 1763.481, 1292.608, 1865.202, 1755.388, 1335.881, 727.916,
545.589, 2269.802, 3152.13, 3312.083, 3012.333, 2751.586, 2548.401,
2863.799, 3252.548, 2577.784, 2373.192, 1889.562, 1238.147, 1759.117,
1732.896, 1359.339, 752.393, 521.439, 2061.208, 3032.467, 3339.89,
3092.35, 2807.905, 2545.574, 2755.354, 3236.159, 2677.463, 2397.792,
1996.564, 1258.061, 1618.8, 1701.341, 1369.019, 790.679, 550.532,
1980.515, 2864.179, 3343.466, 3178.701, 2864.037, 2575.615, 2660.594,
3154.879, 2822.548, 2397.123, 2087.208, 1355.265, 1446.903, 1675.158,
1368.37, 829.423, 569.973, 1985.668, 2655.759, 3321.579, 3264.748,
2924.915, 2630.961, 2586.814, 3031.554, 2982.26, 2391.837, 2162.151,
1501.019, 1277.466, 1644.767, 1362.832, 864.443, 580.59, 2016.137,
2437.503, 3268.481, 3342.639, 3000.739, 2701.252, 2542.323, 2906.25,
3109.213, 2416.145, 2225.942, 1653.046, 1161.459, 1595.291, 1358.297,
892.06, 584.832, 2033.088, 2252.958, 3174.128, 3405.289, 3096.279,
2780.355, 2531.718, 2805.275, 3174.687, 2489.868, 2281.782, 1786.326,
1127.162, 1519.777, 1356.992, 912.617, 582.902, 2124.898, 2113.399,
3025.145, 3424.317, 3180.542, 2849.14, 2538.562, 2708.667, 3166.055,
2592.93, 2306.822, 1890.438, 1153.014, 1401.379, 1344.491, 931.328,
634.217, 2149.562, 2025.775, 2831.546, 3419.181, 3264.521, 2913.641,
2575.308, 2621.754, 3090.068, 2739.807, 2304.329, 1978.437, 1247.624,
1251.636, 1334.21, 940.318, 675.956, 2127.681, 1994.301, 2610.432,
3383.002, 3340.476, 2976.667, 2634.728, 2550.626, 2969.287, 2898.409,
2294.709, 2049.917, 1383.285, 1103.39, 1317.541, 942.961, 704.411,
2102.395, 1999.076, 2397.825, 3304.622, 3396.715, 3043.338, 2702.551,
2500.777, 2839.986, 3016.721, 2309.396, 2104.936, 1519.357, 1002.808,
1279.102, 941.749, 717.39, 2109.249, 2006.351, 2231.959, 3184.807,
3431.22, 3120.714, 2773.577, 2480.512, 2730.776, 3068.892, 2370.003,
2147.419, 1634.995, 975.683, 1214.487, 939.547, 715.582, 2135.013,
2017.646, 2122.971, 3033.355, 3453.678, 3206.32, 2847.497, 2498.27,
2641.612, 3062.713, 2471.761, 2166.962, 1727.575, 1003.716, 1117.559,
939.58, 763.424, 2161.535, 2043.006, 2061.307, 2839.223, 3459.764,
3300.464, 2922.102, 2550.379, 2568.881, 2999.273, 2623.387, 2166.565,
1811.597, 1092.413, 996.192, 943.047, 798.463, 2194.913, 2082.096,
2040.584, 2629.425, 3443.819, 3399.233, 3003.743, 2630.502, 2520.162,
2902.384, 2795.677, 2168.34, 1888.314, 1218.464, 880.525, 942.994,
820.208, 2227.589, 2135.292, 2047.087, 2445.568, 3398.841, 3496.335,
3103.915, 2729.144, 2504.262, 2810.425, 2943.391, 2206.645, 1960.022,
1351.019, 811.11, 926.981, 830.196, 2245.586, 2193.307, 2064.183,
2305.487, 3309.059, 3572.474, 3217.331, 2830.363, 2517.103, 2737.34,
3028.259, 2292.732, 2020.979, 1468.587, 805.174, 886.601, 826.486,
2241.961, 2254.386, 2103.998, 2222.825, 3179.227, 3614.296, 3327.114,
2921.242, 2543.948, 2659.444, 3035.51, 2403.955, 2046.056, 1558.769,
844.31, 821.861, 874.656, 2219.435, 2308.766, 2156.368, 2185.186,
3006.132, 3639.278, 3443.212, 3013.234, 2604.406, 2594.493, 2983.492,
2563.411, 2051.358, 1641.42, 929.937, 735.387, 914.763, 2182.734,
2350.5, 2215.776, 2180.069, 2810.266, 3634.96, 3552.087, 3104.883,
2686.682, 2544.628, 2888.422, 2735.063, 2054.209, 1713.165, 1039.485,
652.87, 935.816, 2141.348, 2373.808, 2271.921, 2185.874, 2625.053,
3581.529, 3633.596, 3194.252, 2770.704, 2510.405, 2778.414, 2861.898,
2080.117, 1767.741, 1143.694, 605.423, 924.007, 2106.719, 2386.125,
2324.505, 2198.176, 2482.926, 3482.596, 3689.137, 3290.633, 2854.093,
2502.224, 2683.577, 2921.101, 2149.579, 1808.661, 1232.019, 607.674,
879.12, 2040.453, 2376.846, 2365.049, 2225.816, 2379.37, 3327.882,
3714.649, 3388.856, 2941.354, 2528.514, 2606.679, 2925.775, 2257.973,
1834.555, 1310.001, 648.13, 876.857, 2021.783, 2340.359, 2394.711,
2258.695, 2317.932, 3124.688, 3710.581, 3480.633, 3019.558, 2580.238,
2535.852, 2866.606, 2404.973, 1837.479, 1380.455, 717.309, 851.087,
2030.384, 2279.831, 2415.146, 2291.831, 2290.815, 2903.497, 3671.682,
3559.943, 3092.394, 2650.125, 2478.655, 2766.146, 2560.275, 1837.524,
1442.428, 799.92, 814.535, 2039.958, 2212.311, 2426.935, 2325.716,
2285.861, 2710.293, 3597.257, 3624.369, 3172.179, 2730.697, 2447.082,
2664.046, 2682.813, 1867.192, 1495.771, 880.503, 782.922, 2031.103,
2157.231, 2423.128, 2359.45, 2291.553, 2568.251, 3486.443, 3668.219,
3262.223, 2814.41, 2445.517, 2581.958, 2747.134, 1941.616, 1539.625,
952.621, 762.39, 2041.318, 2112.705, 2392.939, 2399.467, 2312.487,
2461.637, 3336.101, 3687.095, 3351.396, 2896.013, 2469.602, 2504.225,
2746.593, 2042.562, 1559.541, 1014.341, 802.846, 2015.909, 2085.997,
2344.49, 2435.218, 2346.105, 2405.835, 3147.487, 3689.002, 3445.197,
2976.83, 2526.517, 2441.55, 2694.904, 2186.006, 1564.908, 1074.536,
846.802, 1963.814, 2074.243, 2282.797, 2456.603, 2383.131, 2389.999,
2940.315, 3661.54, 3531.576, 3054.5, 2603.665, 2396.044, 2607.498,
2339.355, 1571.694, 1129.886, 890.393, 1908.408, 2069.048, 2221.994,
2456.749, 2417.99, 2395.595, 2752.741, 3594.318, 3598.937, 3133.603,
2686.737, 2372.994, 2515.126, 2458.047, 1605.272, 1175.918, 931.44,
1865.641, 2056.439, 2174.336, 2434.933, 2447.15, 2408.423, 2611.298,
3484.664, 3640.19, 3217.178, 2767.169, 2375.564, 2438.51, 2517.663,
1678.051, 1211.387, 969.655, 1816.65, 2031.595, 2137.941, 2408.173,
2475.947, 2412.126, 2502.844, 3334.629, 3661.671, 3304.728, 2840.774,
2395.334, 2367.924, 2520.915, 1779.911, 1235.213, 1052.352, 1787.241,
1998.938, 2112.121, 2357.716, 2501.776, 2428.65, 2438.978, 3139.132,
3660.919, 3395.132, 2911.274, 2442.925, 2306.912, 2473.066, 1917.033,
1245.533, 1133.207, 1773.159, 1957.781, 2094.738, 2290.588, 2516.953,
2455.578, 2410.35, 2922.45, 3629.321, 3479.449, 2980.291, 2509.889,
2259.872, 2392.008, 2061.33, 1258.444, 1207.564, 1765.059, 1913.066,
2077.254, 2221.986, 2514.491, 2488.364, 2400.334, 2723.867, 3556.945,
3545.918, 3053.708, 2583.801, 2232.893, 2306.675, 2172.795, 1296.383,
1270.442, 1761.066, 1876.074, 2054.5, 2166.845, 2494.638, 2524.453,
2402.688, 2573.092, 3445.353, 3591.507, 3139.011, 2660.582, 2233.238,
2238.509, 2232.87, 1371.471, 1322.991, 1732.198, 1815.327, 1998.711,
2123.664, 2436.05, 2506.112, 2377.172, 2437.472, 3244.021, 3543.717,
3159.284, 2672.453, 2208.117, 2132.197, 2188.554, 1434.964, 1368.836,
1741.837, 1797.441, 1972.632, 2130.617, 2413.958, 2541.844, 2409.422,
2394.92, 3073.568, 3553.084, 3249.364, 2736.63, 2252.911, 2080.359,
2148.068, 1555.993, 1426.717, 1755.734, 1787.699, 1941.5, 2136.16,
2386.047, 2581.072, 2450.035, 2385.214, 2889.922, 3543.05, 3340.686,
2805.378, 2316.6, 2043.088, 2085.303, 1684.32, 1481.89, 1775.458,
1786.968, 1912.667, 2131.791, 2364.157, 2619.138, 2497.936, 2393.406,
2729.468, 3504.853, 3424.249, 2886.41, 2389.639, 2026.811, 2025.188,
1787.56, 1549.452, 1805.343, 1799.297, 1896.328, 2121.474, 2359.998,
2657.966, 2560.592, 2417.824, 2621.276, 3443.403, 3503.779, 2991.555,
2473.836, 2041.259, 1986.907, 1854.361, 1641.32, 1835.19, 1809.022,
1886.489, 2110.318, 2350.346, 2671.339, 2634.661, 2458.604, 2540.605,
3330.695, 3559.609, 3104.976, 2562.765, 2075.283, 1945.44, 1865.554,
1785.784, 1858.532, 1817.065, 1871.526, 2083.19, 2337.758, 2653.038,
2700.928, 2505.146, 2492.837, 3162.424, 3584.116, 3212.042, 2642.928,
2127.053, 1904.423, 1836.874, 1930.962)), class = "data.frame", row.names = c(NA,
-986L))
> dput(df.f)
structure(list(AgeClass = structure(c(1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L, 2L, 3L, 4L, 5L,
), .Label = c("0-4", "5-9", "10-14", "15-19", "20-24", "25-29",
"30-34", "35-39", "40-44", "45-49", "50-54", "55-59", "60-64",
"65-69", "70-74", "75-79", "80+"), class = "factor"), Year = c(
1963L, 1963L, 1963L, 1963L, 1964L, 1964L, 1964L, 1964L, 1964L,
1964L, 1964L, 1964L, 1964L, 1964L, 1964L, 1964L, 1964L, 1964L,
1964L, 1964L, 1964L, 1965L, 1965L, 1965L, 1965L, 1965L, 1965L,
1965L, 1965L, 1965L, 1965L, 1965L, 1965L, 1965L, 1965L, 1965L,
1965L, 1965L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L, 1966L,
1966L, 1966L, ), Population = c( 2222.025, 2176.911, 2332.267,
3111.964, 1762.017, 1723.872, 1779.322, 1961.153, 2188.16, 2530.019,
2624.555, 2448.425, 2443.353, 3098.345, 3501.391, 3196.981, 2775.151,
2294.375, 2122.456, 2273.263, 3251.321)), class = "data.frame", row.names = c(NA,
-986L))
答案 0 :(得分:3)
您似乎想要做的是用连续的颜色编码填充离散刻度。这样就可以做到(如果您提供数据,会更容易):
colorscale <- colorRampPalette(c("green", "yellow", "red"))(length(levels(df.f$AgeClass)))
ggplot(df.f,aes(x=Year,y=Population,fill=AgeClass))+
geom_area() +
scale_fill_manual(values=setNames(colorscale, levels(df.f$AgeClass)))
答案 1 :(得分:0)
您可以使用scale_fill_gradient2
...
ggplot(df.f,aes(x=Year,y=Population,fill=AgeClass))+
geom_area() +
scale_fill_gradient2(low='green', mid='yellow', high='red')