0

I am new to R and Stack Overflow, but I am creating a simple line graph, and want to play or change the line thickness and the transparency of the lines. I know they need to be within the () of aes argument in geom_line but instead of changing the line thickness and transparency, it just keeps showing up in the legend. It is clearly changing the size of the line, because if I delete the size and alpha argument, the graph changes. But if I just play around with the size= part, nothing happens.

    occupy <- read.csv("BatBoxDescriptiveTablewOccupancy.csv", 
                    stringsAsFactors = FALSE) 

library(ggplot2)
library(dplyr)

occupied <- occupy[occupy$ï..UsedOrNo == 1  , ]

occupied %>%
  ggplot() +
  geom_line(aes(x=Date, y=Occupancy, size=1, alpha=0.05, group = Box.ID, color = Box.ID)) +
  ggtitle("Bat Box Occupancy") +
  theme_classic() +
  scale_x_discrete(limits=c("2021-08-10","2021-08-12", "2021-08-15", "2021-08-17", "2021-08-19", "2021-08-21", "2021-08-23", "2021-08-25", "2021-08-26")) +
  ylab("Number of Individual Bats in Box")

size and alpha in legend

Thanks for the help!

r2evans
  • 141,215
  • 6
  • 77
  • 149
S-Kitty
  • 1
  • 1
  • 2
    Move size and alpha outside of the aes definition – Dave2e Jan 26 '22 at 03:27
  • 4
    In general, it is rare to assign a static constant to aesthetics *inside of `aes`*, instead keeping them within the `geom_*` (or `stat_*` or whatever). When defined *inside* of `aes(..)`, ggplot tries to correlate the variable/symbol with the rows of data, and if it is a static-constant, then it assigns the same value to all geom things (points, lines, etc). And since things inside `aes(.)` tend to be thought of as `factor`s instead of literal values, `color=1` is just one group of colors (try `aes(color="red")` to see what I mean, not red). – r2evans Jan 26 '22 at 03:41
  • 1
    BTW, you may also need to add `guides(size="none", alpha="none")`. – r2evans Jan 26 '22 at 03:44
  • 1
    Relevant background: https://stackoverflow.com/questions/41863049/when-does-the-argument-go-inside-or-outside-aes – Jon Spring Jan 26 '22 at 04:46

1 Answers1

0

Thank you! the Relevant Background information from Jon Spring helped me to fully understand the use of the aes(). and moving them outside the aes argument like Dave2e suggested is the key.

  geom_line(aes(x=Date, y=Occupancy, group = Box.ID, color = Box.ID,), size=3, alpha=0.3)

now works but my legend is blank, but that is another issue...

S-Kitty
  • 1
  • 1