Assigning Unique Colors To Multiple Lines on a Graph
You could use a palette, e.g. built in rainbow
. However 100 colors may not be very distinguishable.
clr <- rainbow(num.chains) ## create `num.chains` colors
matplot(chain.states, type='l', lty=1, col=clr, ylim=c(0, 9),
ylab='state', xlab='time')
abline(h=1, lty=3)
abline(h=8, lty=3)
Multiple Line Plots in ggplot with different colors of points and legend for line and points
You can differentiate point and lines by using fill
and color
argument for example. Color for lines and fill for points while choosing a shape of points that allow fillings (such as shape = 21
):
ggplot(data, aes(x=tmu, y=Value, color = Method, group = Method)) +
geom_line(size = .3, position = pd) +
geom_point(aes(fill = cases),color = "black", shape = 21,size = 2, position = pd) +
labs(fill = "") +
theme(legend.position="bottom")
Or you can pass different color
arguments into geom_line
and geom_point
:
ggplot(data, aes(x=tmu, y=Value, group = Method)) +
geom_line(aes(color = Method), size = .3, position = pd) +
geom_point(aes(color = cases),size = 2, shape = 18, position = pd) +
labs(fill = "") +
theme(legend.position="bottom")
Does it answer your question ?
NB: For some reasons, I can't upload images of the output plot... sorry for that
How to colour box plot lines of each unique value of data?
The reason that no the x-label doesn't appear is because you write axis.title.x = element_blank()
. This effectively removes the label. In order to get colored lines, you should put aes(group = Binomial, color = Binomial)
and remove colour = 'black'
. However, with this many colors you won't be able to see the differences. Anyway, below is a slightly cleaned-up version of your code with the suggested edits.
# Graph plots
r <- ggplot(News, aes(x = Sex, y = log10(MaleFemale.max.longevity), fill = Sex)) +
geom_boxplot(color="grey40", outlier.alpha=0.0) +
stat_summary(fun.y=mean, geom="point", pch="-", color="white", size=8,
position = position_dodge(width=0.75)) +
geom_point(size=2, alpha=0.6, aes(group=Sex),
position = position_dodge(width=0.75)) +
geom_line(aes(colour = Binomial, group = Binomial), alpha = 0.6) +
scale_fill_manual(values=c("#969696","#74c476")) +
theme(axis.text.x = element_text(colour = "black"),
axis.text.y = element_text(colour = "black"),
axis.title.x = element_text(colour = 'black'),
axis.title.y = element_text(colour = "black"),
legend.position = "none") +
labs(y = 'Longevity')
print(r)
Related Topics
How to Flatten/Merge Overlapping Time Periods
Convert Column With Pipe Delimited Data into Dummy Variables
Create Sequence of Repeated Values, in Sequence
Sum Values in a Rolling/Sliding Window
Dummy Variables from a String Variable
What Does %≫% Function Mean in R
R.Exe, Rcmd.Exe, Rscript.Exe and Rterm.Exe: What's the Difference
How to Move Cells With a Value Row-Wise to the Left in a Dataframe
Adding a Regression Line on a Ggplot
Summarizing by Subgroup Percentage in R
Collapsing Rows Where Some Are All Na, Others Are Disjoint With Some Nas
Reshape Multiple Values At Once
Add Correct Century to Dates With Year Provided as "Year Without Century", %Y