Here is the corrected version of your prompt:
Plotting Different Data with Custom Colors
Let’s say we have three data sets: ridge_u_s_summary
, valley_u_s_summary
, and edge_u_s_summary
. Each of these data sets contains measurements of temperature over time.
# Load necessary libraries
library(ggplot2)
# Define the data frames
ridge_u_s_summary <- read.table(text = '"times","means","sd"
"1",1,23.5870433511934,0.937068380991415
"12",2,23.0331950207469,1.1488061017937
"19",3,23.3496395963479,1.02861071580118
"20",4,22.682918395574,1.28095122645134
"21",5,23.1064616862839,1.11960341933558
"22",6,22.4135546334716,1.36699461456579
"23",7,22.9523592814371,1.19411131617966
"24",8,22.5736514522822,1.44525141078227
"25",9,24.0131017964072,1.20022890842346
"2",10,24.4016586040083,1.61518041063122
"3",11,25.6837805462386,1.49361866061128
"4",12,26.0852107809261,2.0335844646935
"5",13,26.5968368080518,1.80035938711879
"6",14,26.7841959972395,2.24353092250421
"7",15,26.502446183953,1.55882287684552
"8",16,26.28759936407,1.72625533400646
"9",17,25.8817558746736,1.24691066538137
"10",18,25.5448412698413,1.45728060915926
"11",19,25.1434910277325,1.08377131492575
"13",20,24.8136616362192,1.32224607164181
"14",21,24.6306135770235,1.00789058764099
"15",22,24.3593328038125,1.32214170798361
"16",23,24.2933093994778,1.02334054495071
"17",24,23.9780778395552,1.34031144743681
"18",25,24.1241503976862,1.16464232030193'," sep = ",", header = T)
valley_u_s_summary <- read.table(text = '"times","means","sd"
"1",1,23.8609523809524,0.941137931036436
"12",2,23.6167464114833,1.36368015448422
"19",3,23.6931023210199,1.09423013467475
"20",4,23.2622807017544,1.40370217291909
"21",5,23.444655116051,1.13978244673363
"22",6,22.9831738437002,1.37794014701823
"23",7,23.2909416748126,1.17933203457316
"24",8,23.2392657621708,1.35015918020873
"25",9,24.302705345502,1.07391752061927
"2",10,24.8187699680511,1.39386829705572
"3",11,25.7716009129442,1.36677999460727
"4",12,26.1712689545092,1.97824543923682
"5",13,26.5006523157208,1.62284855146781
"6",14,26.6692430278884,2.08567545174535
"7",15,26.502446183953,1.55882287684552
"8",16,26.28759936407,1.72625533400646
"9",17,25.8817558746736,1.24691066538137
"10",18,25.5448412698413,1.45728060915926
"11",19,25.1434910277325,1.08377131492575
"13",20,24.8136616362192,1.32224607164181
"14",21,24.6306135770235,1.00789058764099
"15",22,24.3593328038125,1.32214170798361
"16",23,24.2933093994778,1.02334054495071
"17",24,23.9780778395552,1.34031144743681
"18",25,24.1241503976862,1.16464232030193'," sep = ",", header = T)
edge_u_s_summary <- read.table(text = '"times","means","sd"
"1",1,23.1409536784741,1.58548666490834
"2",10,26.7320085166785,2.59539671383782
"3",11,27.6513358778626,2.5977168687079
"4",12,28.586775106082,2.87211533419383
"5",13,28.5709923664122,2.79577350516269
"6",14,29.5764872521246,3.26115806616442
"7",15,28.4104832104832,2.70542254623265
"8",16,28.3307583274274,2.5157045864679
"9",17,26.9131787175989,1.8371272211906
"10",18,26.3352232459249,1.71211772244667
"11",19,25.2531787175989,1.12498732015416
"13",20,24.652728561304,1.24019473277585
"14",21,24.4688591703057,0.99064927009491
"15",22,23.9340425531915,1.16463318058244
"16",23,24.0581058951965,0.987431147782684
"17",24,23.4854609929078,1.19542300490208
"18",25,23.6280334728033,0.977115814231141'," sep = ",", header = T)
# Load necessary libraries
library(ggplot2)
# Bind the data frames together
df <- rbind(edge_u_s_summary, valley_u_s_summary, ridge_u_s_summary)
ggplot(df, aes(times, means, color = variable)) +
geom_errorbar(aes(ymin = means - sd, ymax = means + sd)) +
geom_line() +
theme_classic() +
scale_color_manual(values = c("edge", "valley", "ridge"), name = "Legend")
The Result
When we run the code above, we get a plot with three lines that represent each data set. Each line has an error bar indicating its standard deviation. The x-axis represents time, and the y-axis represents temperature.
The legend shows which color corresponds to each data set:
- Edge
- Valley
- Ridge
Tips
To customize the appearance of your plot, you can modify various parameters in the ggplot
function, such as changing the theme or adding additional aesthetics. For example, you could add a title or labels to the axes using the labs
function.
labs(x = "Time", y = "Temperature in Understory During January to April")
By adjusting these parameters, you can tailor your plot to suit your needs and communicate your findings more effectively.
Last modified on 2025-02-01