Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R GGplot不生成直线图的线性y轴_R_Ggplot2 - Fatal编程技术网

R GGplot不生成直线图的线性y轴

R GGplot不生成直线图的线性y轴,r,ggplot2,R,Ggplot2,我对R很陌生,所以这可能是一个简单的解决方法 我正在尝试创建一个折线图,绘制一年中疫苗的平均全球免疫接种率。我已经创建了我的数据集,如下所示: Year <- c("1991","1992","1993","1994","1995","1996", "1997","1998","1999","2000&

我对R很陌生,所以这可能是一个简单的解决方法

我正在尝试创建一个折线图,绘制一年中疫苗的平均全球免疫接种率。我已经创建了我的数据集,如下所示:

Year <- c("1991","1992","1993","1994","1995","1996", "1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007",
          "2008","2009","2010","2011","2012","2013","2014","2015","2016","2017","2018")

Average_Global_Immunisation_Rate <- c("1.453125","2.234375","3.322917", "3.906250","4.703125","6.411458","10.598958","15.348958","20.776042",                                    "25.265625","29.932292","35.755208","39.250000","42.343750","45.343750","48.177083","52.567708","58.270833",                         "69.161458","75.156250","79.677083","81.911458","84.968750","86.072917","87.151042","87.677083","87.265625","87.281250")

#create new data set from averages and year values

df.AGIR <- data.frame(Year,Average_Global_Immunisation_Rate)
View(df.AGIR)

Year显示的数据当前存储为字符向量:

class(Average_Global_Immunisation_Rate)
[1] "character"
class(Year)
[1] "character"
您需要将数据存储为数字向量:

Year <- as.numeric(Year)
Average_Global_Immunisation_Rate <- as.numeric(Average_Global_Immunisation_Rate)
df.AGIR <- data.frame(Year,Average_Global_Immunisation_Rate)
ggplot(df.AGIR, aes(x = Year, y = Average_Global_Immunisation_Rate)) +
   geom_point()

完美运作的一年。非常感谢你的帮助!