fixed the issue. Will look into that further Several suggestions for consideration... 1: Wrangle your data frame before feeding it into ggplot(). Since trait is a categorical variable, you can specify its levels as a factor explicitly.
wish help you to fix your issue If you rename your columns of the original data frame and then melt it into long format withreshape2::melt, it's much easier to handle in ggplot2. By specifying the color and shape aesthetics in the ggplot command, and specifying the scales for the colors and shapes manually, the legend will appear.
I hope this helps . Convert your data to "long" format and you can then map Used and Available to a color aesthetic. This makes it easier to distinguish them, reduces the amount of code needed, and makes it easy to dodge them (using position_dodge()) so they don't overlap:
will help you We can use duplicated or any similar function to detect the overlap, then we can use R indexing with jitter to apply jitter selectively. I wrote it as a function:
selective_jitter <- function(x, # x = x co-ordinate
y, # y = y co-ordinate
g # g = group
x <- as.numeric(x)
y <- as.numeric(y)
a <- cbind(x, y)
a[duplicated(a)] <- jitter(a[duplicated(a)], amount = .15) # amount could be made a parameter
final <- cbind(a, g)
data <- as.data.frame(selective_jitter(data$x, data$y, data$type))
ggplot() + geom_point(data = data, aes(x=x,y=y, color = g, fill = type), size = 2, shape = 25)