Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.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 为什么geom_线()不通过geom_点()连接?_R_Ggplot2_Plot - Fatal编程技术网

R 为什么geom_线()不通过geom_点()连接?

R 为什么geom_线()不通过geom_点()连接?,r,ggplot2,plot,R,Ggplot2,Plot,问题:为什么geom_线()没有通过geom_点()连接 我有: 用 ggplot(a, aes(x = month, color = year, fill = year)) + scale_color_manual(values = colsze) + scale_fill_manual(values = alpha(colsze, .2)) + scale_x_discrete(labels = c("January", "Fe

问题:为什么
geom_线()
没有通过
geom_点()
连接

我有:

ggplot(a, 
       aes(x = month, color = year, fill = year)) +
  scale_color_manual(values = colsze) + 
  scale_fill_manual(values = alpha(colsze, .2)) + 
  scale_x_discrete(labels = c("January", "February", "March", "April", "May", 
                              "June", "July", "August", "Septemer", 
                              "October", "November", "December")) +
  geom_point(aes(y = n), size = 4, shape=19) +
  geom_line(aes(y = n)) +
  scale_y_continuous(breaks = seq(0, 120, 10), limits = c(0, 120)) +
  facet_wrap(.~year)
我不明白为什么这不起作用?例如,以下教程,如

geom_line()
似乎出现在图例中,但未出现在绘图中

a <- structure(list(month = structure(c(4L, 1L, 4L, 7L, 1L, 9L, 2L, 
8L, 8L, 10L, 7L, 10L, 9L, 9L, 9L, 2L, 10L, 7L, 4L, 2L, 2L, 3L, 
11L, 11L, 12L, 9L, 12L, 10L, 10L, 10L, 11L, 5L, 10L, 10L, 10L, 
10L, 10L, 12L, 11L, 7L, 12L, 6L, 9L, 9L, 9L, 7L, 9L, 4L, 12L, 
12L, 11L, 3L, 3L, 11L, 11L, 11L, 7L, 11L, 12L, 12L, 12L, 2L, 
4L, 1L, 11L, 11L, 1L, 4L, 8L, 2L, 10L, 5L, 5L, 6L, 7L, 11L, 11L, 
11L, 11L, 11L, 12L, 11L, 10L, 7L, 12L, 9L, 9L, 7L, 10L, 8L, 8L, 
5L, 9L, 10L, 9L, 3L, 8L, 10L, 10L, 8L), .Label = c("1", "2", 
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12"), class = "factor"), 
    year = structure(c(3L, 3L, 2L, 1L, 4L, 4L, 4L, 1L, 1L, 1L, 
    3L, 1L, 2L, 1L, 1L, 3L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 
    1L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 
    4L, 4L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 
    2L, 4L, 1L, 3L, 3L, 3L, 2L, 3L, 2L, 2L, 1L, 2L, 2L, 1L, 4L, 
    2L, 1L, 1L, 4L, 4L, 2L, 2L, 4L, 4L, 2L, 3L, 3L, 3L, 4L, 4L, 
    1L, 1L, 3L, 4L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 1L, 1L, 1L
    ), .Label = c("2017", "2018", "2019", "2020"), class = "factor"), 
    n = c(92L, 95L, 83L, 95L, 70L, 88L, 94L, 103L, 103L, 98L, 
    95L, 98L, 90L, 89L, 89L, 76L, 98L, 97L, 79L, 103L, 103L, 
    111L, 104L, 104L, 73L, 89L, 73L, 107L, 107L, 107L, 88L, 111L, 
    107L, 107L, 107L, 107L, 107L, 73L, 104L, 78L, 87L, 92L, 90L, 
    90L, 90L, 78L, 89L, 92L, 98L, 98L, 85L, 111L, 111L, 85L, 
    85L, 85L, 97L, 104L, 73L, 73L, 73L, 71L, 92L, 99L, 85L, 104L, 
    99L, 83L, 103L, 94L, 90L, 90L, 90L, 92L, 97L, 85L, 85L, 88L, 
    88L, 85L, 73L, 89L, 107L, 97L, 87L, 89L, 89L, 95L, 96L, 103L, 
    103L, 75L, 90L, 90L, 90L, 88L, 87L, 98L, 98L, 103L)), row.names = c(NA, 
-100L), groups = structure(list(month = structure(c(1L, 1L, 1L, 
2L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 7L, 
7L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 
12L, 12L, 12L), .Label = c("1", "2", "3", "4", "5", "6", "7", 
"8", "9", "10", "11", "12"), class = "factor"), year = structure(c(2L, 
3L, 4L, 1L, 2L, 3L, 4L, 1L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 4L, 1L, 
2L, 3L, 4L, 1L, 3L, 1L, 2L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 
1L, 3L, 4L), .Label = c("2017", "2018", "2019", "2020"), class = "factor"), 
    .rows = structure(list(c(64L, 67L), 2L, 5L, 20:21, 62L, 16L, 
        c(7L, 70L), c(22L, 52L, 53L), 96L, 19L, c(3L, 68L), c(1L, 
        48L, 63L), 72:73, 92L, 32L, c(42L, 74L), 4L, c(40L, 46L
        ), c(11L, 88L), c(18L, 57L, 75L, 84L), c(8L, 9L, 69L, 
        90L, 91L, 100L), 97L, c(14L, 15L, 26L, 47L, 86L, 87L), 
        c(13L, 43L, 44L, 45L, 93L, 95L), 6L, c(10L, 12L, 17L, 
        98L, 99L), c(71L, 94L), c(28L, 29L, 30L, 33L, 34L, 35L, 
        36L, 37L, 83L), 89L, c(23L, 24L, 39L, 58L, 66L), c(51L, 
        54L, 55L, 56L, 65L, 76L, 77L, 80L), 82L, c(31L, 78L, 
        79L), 49:50, c(25L, 27L, 38L, 59L, 60L, 61L, 81L), c(41L, 
        85L)), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), row.names = c(NA, 36L), class = c("tbl_df", 
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"))
a试试这个:

ggplot(a,
aes(x=数字(月),颜色=年,填充=年)+
#比例\颜色\手动(值=colsze)+
#刻度填充手动(值=alpha(colsze,.2))+
标度x连续(断裂=c(1,2,3,4,5,6,7,8,9,10,11,12),
标签=c(“一月”、“二月”、“三月”、“四月”、“五月”,
“六月”、“七月”、“八月”、“九月”,
“10月”、“11月”、“12月”)+
几何点(aes(y=n),尺寸=4,形状=19)+
几何线(aes(y=n))+
刻度连续(断开=顺序(0,120,10),极限=c(0,120))+
面层(年)
我对这两行进行了注释,因为在您的可复制示例中没有变量
colsze


问题是,
月份
是一个
系数
,必须首先转换为
数值
。为了获得更好的可视化效果,请评估是否将
x
轴上的标签旋转45°

让我来试试!我同意莱昂纳多的解决方案和建议。