当大小已经由另一个变量确定时,ggplot 使默认点大小更大

问题描述

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

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

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

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

enter image description here

{
  #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,color = parm_nmShort))  +
          
          geom_point() +  #add data point plot
          
          geom_line() +   #add line plot
          
          #geom_point(aes(y = lrl,shape = parm_nmShort)) +
          geom_point(aes(x= date,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","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)
  }}

解决方法

经过多次尝试,我找到了自己问题的答案。我想我会留下这个问题,因为我在网上找到的所有解决方案都不适合我,但这段代码却可以。

          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 中包含 groupshape作为 parm_nmShort,我无法手动更改这些值。我不知道是不是因为我的整个脚本中有多个 geom_point,所以它可能不知道要更改哪个。

enter image description here