散点图中并不是所有的值

问题描述 投票:0回答:1

我创建了一个室内用散点图ggplot,但它并没有显示所有值。在该图应该是超过200点,但它只有30分左右。我认为,他们趴在彼此顶部。因此,我想改变点的大小。可以发现很多次的值应该比可以发现,只有几次较大的值。我不知道如何做到这一点,不幸的是,我不能在互联网上找到一个解决方案。我希望有人能帮助我。谢谢!这是我的skript:

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, 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, 6L, 5L, 4L, 4L, 5L, 5L, 6L, 5L, 5L, 6L, 5L, 
  6L, 6L, 6L, 6L, 6L, 6L, 5L, 4L, 3L, 2L, 2L, 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))
r ggplot2
1个回答
0
投票

我们可以做类似下面的情节之前的中间步骤

libarary(dplyr)
heading_winddirection %>% group_by(winddirection,heading) %>% mutate(n=n()) -> heading_winddirection

然后

... + geom_point(stat="identity",aes(size=n)) + ...
© www.soinside.com 2019 - 2024. All rights reserved.