0

I am fairly new to R and I have the following queries :

I am trying to generate a plot in R which has multiple lines (data series each weeks of months from 2020-09-01 to 2021-05-26). Each of these lines is a category and I want it to have a unique color.

csv

Currently my code is setup in this way :

GEE<-read.csv("GEE.CSV")
library(ggplot2)

# Plot the Line chart.
plot(v,type = "o",col = "red", xlab = "Month", ylab = "Crops", 
   main = "Crops chart")

lines(t, type = "o", col = "blue")
Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
  • Try to create [a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). In your current code, `GEE` is not used and it is unclear what `v` and `t` are. (Note also that you're loading `ggplot2` but by using `plot()`, you're not using it.) – iNyar Aug 25 '21 at 18:28
  • Thank u for your answer , I try to writ this code use ggplot2 but also i get error – Mustafa Alhealy Aug 25 '21 at 23:12
  • You need to put the full code and a sample of your data frame. Otherwise, we cannot really help you. Try to do one thing at a time. – iNyar Aug 26 '21 at 04:02

1 Answers1

0

To assign different colors to your lines, you need to assign a specific column (category variable) to col = or color = rather than forcing it to be blue or red.

If your data does not contain this information yet, add a new column with the name of the category for each row.

iNyar
  • 1,916
  • 1
  • 17
  • 31