0

my code is

ggplot(output1, aes(Year, SuPDem, color = as.factor(v2x_regime))) +
  geom_line(size = 0.6) +
  scale_color_manual(values = c("orange", "blue")) +
theme_minimal(base_size = 5)

The index (v2x_regime) is a binary index. 0 indicates autocracy, 1 indicates democracy. I would like to label the lines as democracy and autocracy. How can I do that?

user19562955
  • 293
  • 1
  • 9
  • 1
    `scale_color_manual(values = c("orange", "blue"), labels = c("demo", "auto"))` – Paul Stafford Allen Oct 06 '22 at 13:01
  • 1
    I suggest naming the values and labels to remove ambiguity. For instance, `values=c("0"="orange", "1"="blue")`, same for labels. While it is likely intuitive with 0s and 1s, there are times when it many behave not as intuitively, and (imho) it's better to be in the habit of doing that so that you don't silently mis-label/mis-color layers. (FYI, even if the underlying value is numeric or integer, the name component `"0"=` is always a string; I quote the `0` here because `c(0="a")` produces a parsing error while `c("0"="a")` does not.) – r2evans Oct 06 '22 at 13:18
  • Many thanks!! When there are different columns it is easier to plot using linear regression. In my case, I am trying to plot two different values of a column. Could you help me plotting the same dataset but using linear regression? – user19562955 Oct 06 '22 at 13:27
  • That sounds like a completely different question. Post a new question and include some sample data. But generally, it is easier to convert your data from wide to long format so that the values are in a single column. [See the FAQ on transforming from wide to long](https://stackoverflow.com/q/2185252/903061). – Gregor Thomas Oct 06 '22 at 15:08
  • Sure, I just asked. Thank you – user19562955 Oct 06 '22 at 15:19

0 Answers0