Geom_point将点设置为错误的值 [英] Geom_point putting dots at wrong values

查看:46
本文介绍了Geom_point将点设置为错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据,我正试图用这些数据绘制带有点的非常简单的线图.出于某种原因,当其前1300点的值在1300附近时,其前1600点的值将高于1600.

  dput(数据)结构(列表(y_value = c(1143L,1133L,1148L,1155L,1149L,1144L,1181L,1164L,1178L,1173L,1176L,1209L,1284L,1286L,1283L,1288L,1362L,1396L,1599L,1583L,1606L,1645L,1653L,1662L),日期= c("2014-1","2014-2","2014-3","2014-4","2014-5","2014-6","2014-7","2014-8","2014-9","2014-10","2014-11","2014-12","2015-1","2015-2","2015-3","2015-4","2015-5","2015-6","2015-7","2015-8","2015-9","2015-10","2015-11","2015-12"),年份= c(2014、2014、2014、2014、2014、2014、2014,2014、2014、2014、2014、2014、2015、2015、2015、2015、2015、2015,2015,2015,2015,2015,2015,2015,2015)),row.names = c(NA,-24L),class = c("tbl_df",(tbl),"data.frame"))数据%&%;%ggplot(aes(x =日期,y = y_value,组=年))+geom_line()+geom_point()+facet_grid(facets =.〜year,scale =免费",空间=免费",开关="x")+theme_bw()+主题(axis.text.x = element_blank(),panel.spacing.x = unit(0,"line")) 

我缺少明显的东西吗?因为在这一点上我有点困惑.

我们非常感谢您的帮助.谢谢!

解决方案

因为x按字母顺序排序,转换为日期,然后使用

I have the following data, with which I'm trying to make a pretty simple line plot with dots. For some reason, the first three points of 2015 get placed with a value above 1600 when their value is around 1300.

dput(data)
structure(list(y_value = c(1143L, 1133L, 1148L, 1155L, 1149L, 
1144L, 1181L, 1164L, 1178L, 1173L, 1176L, 1209L, 1284L, 1286L, 
1283L, 1288L, 1362L, 1396L, 1599L, 1583L, 1606L, 1645L, 1653L, 
1662L), Date = c("2014-1", "2014-2", "2014-3", "2014-4", "2014-5", 
"2014-6", "2014-7", "2014-8", "2014-9", "2014-10", "2014-11", 
"2014-12", "2015-1", "2015-2", "2015-3", "2015-4", "2015-5", 
"2015-6", "2015-7", "2015-8", "2015-9", "2015-10", "2015-11", 
"2015-12"), year = c(2014, 2014, 2014, 2014, 2014, 2014, 2014, 
2014, 2014, 2014, 2014, 2014, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015)), row.names = c(NA, -24L), class = c("tbl_df", 
"tbl", "data.frame"))

data %>%
  ggplot(aes(x = Date, y=y_value, group=year))+
  geom_line()+
  geom_point()+
  facet_grid(facets = .~year, scale="free", space="free", switch = "x")+
  theme_bw()+
  theme(axis.text.x = element_blank(),
        panel.spacing.x = unit(0,"line"))


Am I missing something obvious? Because I'm a bit baffled at this point.

Any help is much appreciated. Thanks!

解决方案

Because x is sorted alphabetically, convert to date, then use scale_x_date() to format the date labels:

data$Date <- as.Date(paste0(data$Date, "-1"), "%Y-%m-%d")

ggplot(data, aes(x = Date, y=y_value, group=year))+
  geom_line()+
  geom_point()+
  facet_grid(facets = .~year, scale="free", space="free", switch = "x")+
  scale_x_date() +
  theme_bw()+
  theme(axis.text.x = element_blank(),
        panel.spacing.x = unit(0,"line"))

这篇关于Geom_point将点设置为错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆