0

i'm newbie and i really need some help with my data. First of all, i can't change the legend to show the shape of points. And secondly i need to show just 2 out of 3 categorial variables (just 2 and 3, not 1).

alikvot <- data_oliga$alikvot

#selecting categorial variables

alikvot = sample(c("1", "2", "3"), 648, replace = TRUE)
alikvot = as.factor(alikvot)
alikvot = cbind(data_oliga, alikvot)

#creating scatterplot

Graf_oliga = ggplot(data = data_oliga, aes (x = konc_v, y = Area, 
                                            colour = factor(alikvot), shape = alikvot, group = alikvot)) 

Graf_oliga + 
  geom_point() +
  theme(axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank()) +
  scale_shape_identity() +
  xlab("Abs * 400") +
  labs(colour = "Alikvot", shape = alikvot) +
  scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x)) +
  scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x))

enter image description here

I know that the code is so messed up. Thanks for any help

Data looks like that:

ID oliga alikvot Area Abs * 400
39/18 1 1234 56789
39/18 1 3465 56789
39/18 2 1456 56789
39/18 2 3546 23187
39/18 3 11681 78624
39/18 3 1681 12357
50/18 1 45654 23394
50/18 1 1156 14653
50/18 2 5467 42358
50/18 2 9241 32186
50/18 3 7864 32168
50/18 3 6821 48918
The24xxx
  • 3
  • 2
  • 1
    Welcome to SO! To help us to help you could you please make your issue reproducible by sharing a sample of your **data**? See [how to make a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Simply type `dput(NAME_OF_DATASET)` into the console and copy & paste the output starting with `structure(....` into your post. If your dataset has a lot of observations you could do `dput(head(NAME_OF_DATASET, 20))` for the first twenty rows of data. – stefan Jun 26 '21 at 15:57
  • 1
    .. . for the legend you could try with `scale_shape_identity(guide = "legend")` as `scale_xxx_identity` will not create a legend by default. Your second issue sounds like a filtering issue, i.e. instead of making use of the whole data you could use `data_oliga[data_oliga$alkivot %in% c(2, 3), ]` – stefan Jun 26 '21 at 15:59
  • added table with datas. – The24xxx Jun 26 '21 at 16:20
  • scale_shape_identity(guide = "legend") just showed another legend with just shapes, no colours. Also it somehow showed 5 shapes instead of 3. Filtering also didn't help. – The24xxx Jun 26 '21 at 16:25

1 Answers1

0

Try this. If you want the legends to get merged you have to map the same variables on the color and shape aesthetic, i.e. factor(alikvot), and (!!) set the same labels inside labs().

Not sure what you tried to achieve with scale_shape_identity. So I simply removed it. If you want specific shapes then make use of scale_shape_manual(values = c(...)).

library(ggplot2)
library(scales)

data_oliga_filtered <- data_oliga[data_oliga$alikvot %in% c(2, 3),]
Graf_oliga = ggplot(data = data_oliga_filtered, aes (x = `Abs.*.400`, y = Area, 
                                            colour = factor(alikvot), shape = factor(alikvot)))
Graf_oliga + 
  geom_point() +
  theme(axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank()) +
  xlab("Abs * 400") +
  labs(colour = "Alikvot", shape = "Alikvot") +
  scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x)) +
  scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x))

stefan
  • 90,330
  • 6
  • 25
  • 51