我用ggplot创建了一个散点图,但它没有显示所有值。在该图中,应该超过200点,但只有30点左右。我认为它们彼此叠在一起。因此,我想更改积分的大小。可以多次发现的值应大于只能几次发现的值。我不知道该怎么做,很遗憾,我在互联网上找不到解决方案。我希望有人能帮助我。谢谢! 这是我的小偷:
options(stringsAsFactors = FALSE)
input1 <- "C:\\Users\\heading_winddirection.csv"
heading_winddirection <- read.csv(input1, sep=";")
library(lubridate)
library(ggplot2)
dput(heading_winddirection)
plot <-ggplot(heading_winddirection, aes(x=as.character(winddirection), y=as.character(heading))) + geom_point(stat="identity") + geom_smooth(method=lm , color="red", se=FALSE)
plot <-plot +theme(legend.position="none") + theme_bw()+
scale_y_discrete(labels=c("1" = "North", "2" = "North East", "3" = "East", "4"= "South East", "5"= "South", "6"="South West", "7"="West", "8"="North West"))+
scale_x_discrete(labels=c("1" = "North", "2" = "North East", "3" = "East", "4"= "South East", "5"= "South", "6"="South West", "7"="West", "8"="North West"))
print(plot)
我的数据
structure(list(heading = c(1L, 7L, 1L, 5L, 5L, 1L, 5L, 5L, 1L,
3L, 7L, 7L, 7L, 7L, 1L, 3L, 5L, 7L, 1L, 5L, 1L, 1L, 5L, 1L, 5L,
1L, 3L, 5L, 5L, 1L, 5L, 7L, 5L, 5L, 1L, 1L, 5L, 1L, 5L, 5L, 5L,
1L, 1L, 8L, 5L, 5L, 1L, 5L, 5L, 8L, 5L, 5L, 1L, 1L, 1L, 1L, 2L,
5L, 1L, 1L, 1L, 1L, 1L, 5L, 7L, 5L, 1L, 5L, 1L, 5L, 1L, 1L, 5L,
5L, 5L, 1L, 5L, 5L, 7L, 5L, 5L, 1L, 1L, 1L, 5L, 1L, 1L, 5L, 1L,
7L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 7L, 1L, 1L, 1L, 1L, 1L, 1L, 5L,
5L, 1L, 1L, 1L, 1L, 7L, 1L, 5L, 5L, 5L, 1L, 3L, 5L, 5L, 5L, 5L,
5L, 1L, 5L, 1L, 1L, 4L, 4L,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L, 1L, 2L, 4L, 1L, 6L,
5L, 6L, 6L, 6L, 6L, 5L, 6L, 5L, 4L, 1L, 8L, 5L, 5L, 5L, 4L, 4L,
5L, 5L, 4L, 4L, 5L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 4L, 4L,
4L, 4L, 5L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 4L, 6L, 5L, 6L, 6L, 5L,
5L, 5L, 5L, 5L, 6L, 6L, 5L, 5L, 7L, 6L, 3L, 4L)), class = "data.frame", row.names = c(NA,
-224L))
答案 0 :(得分:0)
我们可以在下图之前做一个中间步骤
libarary(dplyr)
heading_winddirection %>% group_by(winddirection,heading) %>% mutate(n=n()) -> heading_winddirection
然后
... + geom_point(stat="identity",aes(size=n)) + ...