首页 > 解决方案 > 当大小已经由另一个变量确定时,ggplot 使默认点大小变大

问题描述

我正在尝试显示包含未检测到的数据。对于 ND,我希望有一个不同大小的圆形轮廓,这样线条就不会相互重叠。我几乎有我想要的东西,但是对于参数cis-DCE,圆形轮廓只会使点看起来更大,而不是成为一个独特的轮廓。如何将大小归因于参数并使起始大小更大?

我将包含我用于绘图的所有代码,但我现在正在专门研究这一点。

geom_point(aes(x= date, y = lrl, group = parm_nmShort, size = parm_nmShort), shape = 1) + #marking lower limit

我也知道我可以使用facet_wraps并且我之前已经这样做了,但从历史上看,这些数据已显示在一个图表中,但没有识别 ND,我不想彻底改变数据的显示并混淆任何人。

在此处输入图像描述

{
  #graphing
  
  # folder where you want the graphs to be saved:
  results <- 'C:/Users/cbuckley/OneDrive - DOI/Documents/Projects/New Haven/Data/Graphs/'  
  
  {
    
    VOC.graph <- function(df, na.rm = TRUE, ...){
    
  
      df$parm_nmShort <- factor(df$parm_nm, levels = c("cis.1.2.Dichloroethene_77093",
                                                       "Trichloroethene_34485", 
                                                       "Tetrachloroethene_34475"), 
                                labels = c("cis-DCE", "TCE", "PCE"))  
      
      # create list of sites in data to loop over 
      site_list <- unique(df$site_nm)
      
      # create for loop to produce ggplot2 graphs 
      for (i in seq_along(site_list)) { 
        
        # create plot for each county in df 
        plot <- 
          ggplot(subset(df, df$site_nm==site_list[i]),
                 aes(x = date, y = result, 
                     group = parm_nmShort, 
                     color = parm_nmShort))  +
          
          geom_point() +  #add data point plot
          
          geom_line() +   #add line plot
          
          #geom_point(aes(y = lrl, group = parm_nmShort, shape = parm_nmShort)) +
          geom_point(aes(x= date, y = lrl, group = parm_nmShort, size = parm_nmShort), shape = 1) + #marking lower limit
          
          #scale_shape_manual(values = c("23","24","25")) + #create outlier shapes
          
          #facet_wrap(~parm_nmShort) +
          
          ggtitle(site_list[i]) + #name graphs well names
          
          #  theme(legend.position="none") + #removed legend
          
          labs(x = "Year", y = expression(paste("Value, ug/L"))) +  #add x and y label titles
          
          theme_article() + #remove grey boxes, outline graph in black
          
          theme(legend.title = element_blank()) + #removes legend title
        
          scale_x_date(labels = date_format("%y"),
                       limits = as.Date(c("2000-01-01","2021-01-01"))) #+ # set x axis for all graphs
          
        
        #  geom_hline(yintercept = 5) #+ #add 5ug/L contaminant limit horizontal line
        
        #  theme(axis.text.x = element_text(angle = 45, size = 12, vjust = 1)) + #angles x axis titles 45 deg
        
        
        
        
        
        #  theme(aspect.ratio = 1) +
        #  scale_color_hue(labels = c("cic-DCE", "PCE", "TCE")) +  #change label names  
        #  scale_fill_discrete(breaks = c("PCE", "TCE", "cic-DCE"))
        
        # Code below will let you block out below the resolution limit    
        #    geom_ribbon(aes(ymin = 0, ymax = ###LRL###), fill ="white", color ="grey3") +
        #    geom_line(color ="black", lwd = 1)
        
        
        
        
        #ggsave(plot, 
        #       file=paste(results, "", site_list[i], ".png", sep=''),
        #       scale=1)
        
        # print plots to screen
        print(plot)
      }
    }
    
    #run graphing function with long data set
    VOC.graph(data)
  }}

标签: rggplot2plotgraphgraphing

解决方案


好吧,在玩了很多之后,我找到了自己问题的答案。我想我会留下这个问题,因为我在网上找到的解决方案都不适合我,但这段代码可以。

          geom_point(aes(x= date, y = lrl, group = parm_nmShort, shape = parm_nmShort, size = parm_nmShort)) + #identify non detects
          
          scale_shape_manual(values = c(1,1,1)) +
          
          scale_size_manual(values = c(3,5,7)) +

我不太擅长 R,但由于某种原因,当我没有将aes中的形状作为parm_nmShort包括在内时,我无法手动更改这些值。我不知道是不是因为我的整个脚本中有多个geom_point,所以它可能不知道要更改哪一个。

在此处输入图像描述


推荐阅读