Add circular axis on circular plot - r

I would like to overlay my plot with circles as axis to illustrate probability levels (e.g 0.25; 0.75, 1).
To reproduce the graphic you need these 2 csv files in working directory
https://drive.google.com/open?id=1RsleBYQFlm3ce3xuqTLK-_r9s374yd40
Or since I have been kindly advised by #Gregor in comments here are the headers of my data objects so no downloading is necessary:
dput(head(data))
structure(list(id = 1:6, individual = structure(c(1L, 12L, 23L,
26L, 27L, 28L), .Label = c("Person 1", "Person 10", "Person 11",
"Person 12", "Person 13", "Person 14", "Person 15", "Person 16",
"Person 17", "Person 18", "Person 19", "Person 2", "Person 20",
"Person 21", "Person 22", "Person 23", "Person 24", "Person 25",
"Person 26", "Person 27", "Person 28", "Person 29", "Person 3",
"Person 30", "Person 31", "Person 4", "Person 5", "Person 6",
"Person 7", "Person 8", "Person 9"), class = "factor"), value = c(0.658333333,
0.958333333, 0.720833334, 0.883333333, 0.779166667, 0.9375),
group = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "A", class = "factor")), .Names = c("id",
"individual", "value", "group"), row.names = c(NA, 6L), class = "data.frame")
and second object:
dput(head(label_data))
structure(list(id = 1:6, individual = structure(c(1L, 12L, 23L,
26L, 27L, 28L), .Label = c("Person 1", "Person 10", "Person 11",
"Person 12", "Person 13", "Person 14", "Person 15", "Person 16",
"Person 17", "Person 18", "Person 19", "Person 2", "Person 20",
"Person 21", "Person 22", "Person 23", "Person 24", "Person 25",
"Person 26", "Person 27", "Person 28", "Person 29", "Person 3",
"Person 30", "Person 31", "Person 4", "Person 5", "Person 6",
"Person 7", "Person 8", "Person 9"), class = "factor"), value = c(0.658333333,
0.958333333, 0.720833334, 0.883333333, 0.779166667, 0.9375),
group = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "A", class = "factor"),
hjust = c(0, 0, 0, 0, 0, 0), angle = c(84.375, 73.125, 61.875,
50.625, 39.375, 28.125)), .Names = c("id", "individual",
"value", "group", "hjust", "angle"), row.names = c(NA, 6L), class = "data.frame")
And then run following:
library(tidyverse)
library(ggplot2)
library(plotrix)
data=read.csv(file="data_object_2.csv", header=TRUE, sep=",")
label_data=read.csv(file="label_data_object_2.csv", header=TRUE, sep=",")
empty_bar=1
to_add = data.frame( matrix(NA, empty_bar*nlevels(data$group), ncol(data)) )
colnames(to_add) = colnames(data)
to_add$group=rep(levels(data$group), each=empty_bar)
data=rbind(data, to_add)
data=data %>% arrange(group)
data$id=seq(1, nrow(data))
number_of_bar=nrow(label_data)
angle= 90 - 360 * (label_data$id-0.5) /32
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle<-ifelse(angle < -90, angle+180, angle)
p = ggplot(data, aes(x=as.factor(id), y=value)) +
geom_bar(stat="identity", fill=alpha("skyblue", 0.7)) +
ylim(-0.3,1) +
theme_minimal() +
theme(
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
plot.margin = unit(rep(-1,4), "cm")
) +
coord_polar(start = 0) +
geom_text(data=label_data, aes(x=id, y=value, label=individual, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE ) +
geom_vline(xintercept = 0, color = "grey", linetype = "dashed") +
annotate("text", label = "p=0", x = 0, y = 0, color = "black") +
annotate("text", label = "p=1", x = 0, y = 1, color = "black") +
annotate("text", label = "p=0.5", x = 0, y = 0.5, color = "black")
p
It will result in this:
https://drive.google.com/open?id=1xDOym_nn-x9nrUoKpB9rtg7h7NYIfucF
I would like to overlay with circles indicating probability levels to enhance readability. All the on-line help which I have found is related to common Cartesian graph or geom_circle function which did not work either.
I will really appreciate any help.
Thanks Marek

Here's an option over a simplified version of your code (I didn't want to recreate all the labels, etc, just a pared down version of your chart). I thought about it like this: if this were in regular Cartesian coordinates, you could show an overlay of a probability by making a horizontal line, so in polar coordinates, that line would become a circle. Adding a geom_hline gives you a circle at whatever yintercept you set.
It might be good to label those probabilities; you can figure out what's the best way to do that in your context, but I just made a couple of circles, set the y-breaks to those same values, and moved the y axis title to be near the labels so they had a little explanation. Based on your context, that might not all be necessary.
As an aside, I'd recommend combining these two data frames into one, so you can more easily keep track of things and not have to set different data = arguments in different geoms.
library(tidyverse)
label_data %>%
ggplot(aes(x = individual, y = value)) +
geom_col(width = 0.5, fill = "skyblue", alpha = 0.7) +
geom_hline(yintercept = c(0.5, 0.75, 0.9), color = "gray60") +
scale_y_continuous(limits = c(-0.3, NA), breaks = c(0.5, 0.75, 0.9)) +
theme_minimal() +
theme(panel.grid = element_blank(), axis.title.y = element_text(hjust = 0.87)) +
coord_polar(start = 0) +
labs(x = NULL, y = "Probability")
Created on 2018-06-03 by the reprex package (v0.2.0).

Related

ggplot - Plotting 2 different variables with the same x axis but with different color/shape for these 2 variables

I want to make a graph with date in x axis and pH values on y axis (AM = morning measures and PM = afternoon measures). In my data.frame I have 4 columns : mean_pHAM, sd_pHAM, mean_pHPM and sd_pHPM.
Here it's my code using Rstudio ```
pH1 <- ggplot(para_list_floc) +
aes(x = Date, y = Moy_pHAM) +
geom_point(size=3, color="blue") +
geom_errorbar(aes(ymin =Moy_pHAM-Ecart_type_pHAM, ymax=Moy_pHAM +Ecart_type_pHAM),position=position_dodge(0.05), color="blue") +
geom_point(aes(x=Date, y=Moy_pHPM,size=3, color="red",)) +
geom_errorbar(aes(ymin =Moy_pHPM-Ecart_type_pHPM, ymax=Moy_pHPM +Ecart_type_pHPM),position=position_dodge(0.05), color="red") +
ggtitle("Suivi du pH pendant la phase test") +
theme(plot.title = element_text(size=10,hjust = 0.5,face="bold")) +
ylab("Moy du pH/bac") +
labs(x = "Temps (en jour)") +
theme(axis.text.x = element_text(angle=90))
Like you can see on the picture, I don't know how to have the same size of point but with colors different to see the values from AM and the values from PM measures. And also how to precise that in the legend?
dput(head(para_list_floc,7))
structure(list(Date = structure(8:14, .Label = c("Jour 01", "Jour 02",
"Jour 03", "Jour 04", "Jour 05", "Jour 06", "Jour 07", "Jour 08",
"Jour 09", "Jour 10", "Jour 11", "Jour 12", "Jour 13", "Jour 14",
"Jour 15", "Jour 16", "Jour 17", "Jour 18", "Jour 19", "Jour 20",
"Jour 21", "Jour 22", "Jour 23", "Jour 24", "Jour 25", "Jour 26",
"Jour 27", "Jour 28", "Jour 29"), class = "factor"), Moy_tpAM = c(25.9428571428571,
25.8142857142857, 25.6571428571429, 25.9, 25.9, 25.9333333333333,
25.8047619047619), Ecart_type_tpAM = c(0.120712172424444, 0.101418510567422,
0.116496474502143, 0.104880884817015, 0.0999999999999998, 0.115470053837925,
0.139557122627942), Moy_tpPM = c(NaN, NaN, 26.1190476190476,
26.3285714285714, 26.3333333333333, 26.2761904761905, 26.1095238095238
), Ecart_type_tpPM = c(NA, NA, 0.132736760616823, 0.118923745075814,
0.119721899973786, 0.157812426331902, 0.175797502555531), Moy_pHAM = c(7.7452380952381,
7.58952380952381, 7.75904761904762, 7.69047619047619, 7.74190476190476,
7.70904761904762, 7.76333333333333), Ecart_type_pHAM = c(0.0705421184555048,
0.0633621488332104, 0.0659473094147715, 0.0644574425862669, 0.076001253122501,
0.0599920629670926, 0.0486141268905791), Moy_pHPM = c(NaN, NaN,
7.69285714285714, 7.75285714285714, 7.79380952380952, 7.78142857142857,
7.85666666666667), Ecart_type_pHPM = c(NA, NA, 0.0590883116312234,
0.0551491484197949, 0.0634410112211486, 0.0467210567395167, 0.0531350480693614
), Moy_Oxy = c(5.11714285714286, 5.21380952380952, 5.79380952380952,
5.68666666666667, 5.76571428571429, 5.65428571428571, NaN), Ecart_type_Oxy = c(0.181635427633016,
0.122901431662784, 0.176818443338815, 0.144890763450723, 0.161200850759896,
0.164971859072129, NA), Moy_MES = c(NaN, NaN, 4.47619047619048,
6.66666666666667, 5.45238095238095, 11, 6.14285714285714), Ecart_type_MES = c(NA,
NA, 3.18777426457784, 2.42212028327799, 2.68283787203384, 1.4142135623731,
2.28113380330296), y = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE)), row.names = c(NA, 7L), class = "data.frame")
Your data structure does not easily lend itself to plotting with groupwise colors and dodging. You should reshape it into long format, with one column for mean value, one column for the error size, and one column for the variable (pHAM or pHPM). This means you only need a single geom_point call, a single geom_errorbar call, and allows you map the color to the variable (pHAM or pHPM). This can be done using the tidyverse functions pivot_longer and pivot_wider:
library(tidyverse)
read.csv("paratest2.csv", sep = ";") %>%
group_by(Date) %>%
summarize(Moy_pHAM = mean(pH_AM, na.rm = TRUE),
Moy_pHPM = mean(pH_PM, na.rm = TRUE),
Ecart_type_pHAM = sd(pH_AM, na.rm = TRUE),
Ecart_type_pHPM = sd(pH_PM, na.rm = TRUE)) %>%
filter(Date > "Jour 07") %>%
pivot_longer(-Date, names_pattern = "^(.*)_(.*$)",
names_to = c("measure", "var")) %>%
pivot_wider(names_from = measure, values_from = value) %>%
ggplot(aes(Date, Moy, color = var)) +
geom_point(position = position_dodge(width = 0.5), na.rm = TRUE) +
geom_errorbar(aes(ymin = Moy - Ecart_type, ymax = Moy + Ecart_type),
position = position_dodge(width = 0.5), na.rm = TRUE) +
scale_color_manual(values = c("blue", "red")) +
ggtitle("Suivi du pH pendant la phase test") +
labs(x = "Temps (en jour)", y = "Moy du pH/bac", color = NULL) +
theme(axis.text.x = element_text(angle=90),
plot.title = element_text(size = 10, hjust = 0.5, face = "bold"))

ggplot by group with filter()

I have big dataset with the following format:
structure(list(LOCATION = c("CAN", "CAN", "CAN", "CAN", "CAN",
"CAN", "CAN", "CAN", "CAN", "CAN"), Country = c("Canada", "Canada",
"Canada", "Canada", "Canada", "Canada", "Canada", "Canada", "Canada",
"Canada"), SUBJECT = c("ULABUL99", "ULABUL99", "ULABUL99", "ULABUL99",
"ULABUL99", "ULABUL99", "ULABUL99", "ULABUL99", "ULABUL99", "ULABUL99"
), Subject = c("Unit Labour Cost", "Unit Labour Cost", "Unit Labour Cost",
"Unit Labour Cost", "Unit Labour Cost", "Unit Labour Cost", "Unit Labour Cost",
"Unit Labour Cost", "Unit Labour Cost", "Unit Labour Cost"),
SECTOR = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Sector = c("Total Economy",
"Total Economy", "Total Economy", "Total Economy", "Total Economy",
"Total Economy", "Total Economy", "Total Economy", "Total Economy",
"Total Economy"), MEASURE = c("ST", "ST", "ST", "ST", "ST",
"ST", "ST", "ST", "ST", "ST"), Measure = c("Level, ratio or national currency",
"Level, ratio or national currency", "Level, ratio or national currency",
"Level, ratio or national currency", "Level, ratio or national currency",
"Level, ratio or national currency", "Level, ratio or national currency",
"Level, ratio or national currency", "Level, ratio or national currency",
"Level, ratio or national currency"), FREQUENCY = c("A",
"A", "A", "A", "A", "A", "A", "A", "A", "A"), Frequency = c("Annual",
"Annual", "Annual", "Annual", "Annual", "Annual", "Annual",
"Annual", "Annual", "Annual"), TIME = 1970:1979, Time = 1970:1979,
Value = c(0.1304592, 0.1357066, 0.1430287, 0.1521136, 0.1752398,
0.2018611, 0.2193767, 0.2347496, 0.2470616, 0.2663881), Flag.Codes = c("E",
"E", "E", "E", "E", "E", "E", "E", "E", "E"), Flags = c("Estimated value",
"Estimated value", "Estimated value", "Estimated value",
"Estimated value", "Estimated value", "Estimated value",
"Estimated value", "Estimated value", "Estimated value")), row.names = c(NA,
10L), class = "data.frame")
And I want to draw time plot like the following (for each sector group in a particular country's particular subject, in this case, Germany's Labour Income Share)
I tried to code as follows:
library(ggplot2)
library(tidyr)
df <- read.csv("/Users/ulc.csv", header = TRUE)
fsector = factor(df$SECTOR)
df %>%
filter(df$MEASURE =="ST",
df$SUBJECT == "ULAIRU99",
df$LOCATION == "DEU") %>%
ggplot(aes(x = df$year, y = df$value, color = fsector, linetype = fsector)) +
scale_color_manual(labels=c("Sec 1","Sec 2", "Sec 3", "Sec 4", "Sec 5", "Sec 6", "Sec 7", "Sec 8"), values = 1:8) +
scale_linetype_manual(labels=c("Sec 1","Sec 2", "Sec 3", "Sec 4", "Sec 5", "Sec 6", "Sec 7", "Sec 8"), values = 1:8) +
theme(legend.position = c(0.8, 0.3), legend.title = element_blank()) +
ylab("LIS of Germany by sector") + xlab("year")
But the result does not show any plots and seems like a lot of elements are missing in my code. Maybe should I add geom_line() for each sector? But there seems much simpler way. Any help would be appreciated.
You can try the following code -
library(dplyr)
library(ggplot2)
df %>%
filter(MEASURE =="ST",SUBJECT == "ULAIRU99",LOCATION == "DEU") %>%
mutate(SECTOR = factor(SECTOR)) %>%
ggplot(aes(x = TIME, y = Value, color = SECTOR, linetype = SECTOR)) +
geom_line() +
scale_color_manual(labels=c("Sec 1","Sec 2", "Sec 3", "Sec 4", "Sec 5", "Sec 6", "Sec 7", "Sec 8"), values = 1:8) +
scale_linetype_manual(labels=c("Sec 1","Sec 2", "Sec 3", "Sec 4", "Sec 5", "Sec 6", "Sec 7", "Sec 8"), values = 1:8) +
theme(legend.position = c(0.8, 0.3), legend.title = element_blank()) +
ylab("LIS of Germany by sector") + xlab("year")

Produce a geom_tile plot with multiple legend categories (fill) per tile

I am creating a tile plot for my data shared below. For each tile, there could multiple reasons of failure and I want the tiles to show multiple colors indicating that in a grid.
> coupler.graph
# A tibble: 34 x 3
`Bar Size` Category `Mode of Failure`
<chr> <chr> <chr>
1 No. 4 SSC SMA bar fractured inside grip
2 No. 4 SSC Bar fracture
3 No. 6 SSC Bar pullout
4 No. 6 SSC Bar fracture
5 No. 6 SSC Bar fracture
6 No. 6 GSC Bar fracture
7 No. 6 GSC GC fracture
8 No. 6 GSC Thread failure
9 No. 8 SSC Bar pullout
10 No. 8 SSC Bar fracture
# ... with 24 more rows
I use the following code:
ggplot(coupler.graph) +
aes(x = Category, y = fct_inorder(`Bar Size`), fill = `Mode of Failure`) +
geom_tile(size = 1L) + theme_classic() + scale_fill_hue() +
labs(x = "Splicer Type", y = "Bar Size", title = "Mechanical Coupler Research Summary") +
theme(plot.title = element_text(hjust = 0.5,
margin = margin(10,0,20,0), face = "bold", size = 24),
axis.title.y = element_text(size = 14, margin = margin(t = 0, r = 20, b = 0, l = 0)),
axis.title.x = element_text(size = 14, margin = margin(t = 15, r = 0, b = 0, l = 0)),
legend.title = element_text(size = 16))
Right now they are just overlapping each other. How can I fix this?
> dput(coupler.graph)
structure(list(Category = c("SSC", "SSC", "SSC", "SSC", "GSC",
"SSC", "SSC", "HBC", "GSC", "GSC", "BSC", "SSC", "HBC", "GSC",
"TC", "BSC", "HBC", "GSC", "GSC", "GSC", "TC", "BSC"), `No. Bars` = c(4,
4, 80, 5, 7, 80, 10, 4, 9, 6, 3, 9, 9, 9, 18, 10, 10, 10, 8,
4, 4, 4), `Bar Size` = c("No. 4", "No. 4", "No. 6", "No. 6",
"No. 6", "No. 8", "No. 8", "No. 8", "No. 8", "No. 8", "No. 8",
"No. 10", "No. 10", "No. 10", "No. 10", "No. 10", "No. 10", "No. 10",
"No. 11", "No. 18", "No. 18", "No. 18")), row.names = c(NA, -22L
), class = c("tbl_df", "tbl", "data.frame"))
Thank you
One approach to get at least close to a solution is to facet by category. Try this:
library(ggplot2)
coupler.graph <- read.table(text='row "Bar Size" Category "Mode of Failure"
1 "No. 4" SSC "SMA bar fractured inside grip"
2 "No. 4" SSC "Bar fracture"
3 "No. 6" SSC "Bar pullout"
4 "No. 6" SSC "Bar fracture"
5 "No. 6" SSC "Bar fracture"
6 "No. 6" GSC "Bar fracture"
7 "No. 6" GSC "GC fracture"
8 "No. 6" GSC "Thread failure"
9 "No. 8" SSC "Bar pullout"
10 "No. 8" SSC "Bar fracture"', header = TRUE)
ggplot(coupler.graph, aes(x = Mode.of.Failure, y = forcats::fct_inorder(Bar.Size), fill = Mode.of.Failure)) +
geom_tile(size = 1L, color = "white") +
theme_classic() +
scale_fill_hue() +
scale_x_discrete(expand = expansion(mult = 0.01)) +
facet_wrap(~Category, nrow = 1, scales = "free_x") +
theme(panel.spacing.x = unit(0, "pt"),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())
Created on 2020-06-21 by the reprex package (v0.3.0)

ggplot2 overlay two plots, one legend with manual color selection

i have the following code:
FXX_03_Data_8To11_byAgeRange <- structure(list(F20_AgeRange = c("26 - 30", "31 - 35", "36 - 40",
"41 - 45", "46 - 50", "51 - 55", "56 - 60"),
n_Count = c(5L,13L, 59L, 110L, 52L, 14L, 2L),
Prozent = c(2, 5.1, 23.1, 43.1,20.4, 5.5, 0.8)),
.Names = c("F20_AgeRange", "n_Count", "Prozent"),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -7L))
FXX_03_Data_byAgeRange <- structure(list(F20_AgeRange = c("18 – 25", "26 - 30", "31 - 35",
"36 - 40", "41 - 45", "46 - 50", "51 - 55", "56 - 60"),
n_Count = c(3L,12L, 25L, 65L, 118L, 58L, 19L, 4L),
Prozent = c(1, 3.9, 8.2, 21.4, 38.8, 19.1, 6.2, 1.3)),
.Names = c("F20_AgeRange", "n_Count", "Prozent"),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -8L))
ggplot() +
geom_bar(data = FXX_03_Data_8To11_byAgeRange, aes(x = F20_AgeRange, y = Prozent, fill = "Parents 8 to 11"), stat = "identity", width = 0.4, position = position_nudge(x = 0.25)) +
geom_bar(data = FXX_03_Data_byAgeRange, aes(x = F20_AgeRange, y = Prozent, fill = "Parents accumulated"), stat = "identity", width = 0.4, position = position_nudge(x = - 0.25))
This results in the following plot: Plot
Now how do i change the colors of the bars? I know when i move fill out of aes it will let me define a color, but then i loose the legend....
I recommend a more ggplot-like approach: Merge and tidy both data.frames, and then pass a single data.frame to ggplot and use aesthetics to map groups to visual properties.
library(tidyverse)
full_join(
FXX_03_Data_8To11_byAgeRange, FXX_03_Data_byAgeRange,
by = "F20_AgeRange",
suffix = c(".8To11", ".accumulated")) %>%
gather(Group, Prozent, starts_with("Prozent")) %>%
mutate(Group = sub("Prozent\\.", "", Group)) %>%
ggplot(aes(F20_AgeRange, y = Prozent, fill = Group)) +
geom_bar(stat = "identity", position = "dodge2") +
scale_fill_manual(values = c("8To11" = "red", "accumulated" = "blue"))

ggplot2: Different legend symbols for points and lines

already searched all related threads about this but could not find a solution.
Here is my code and the attached plot result:
g <-ggplot(NDVI2, aes(LAI2, NDVI, colour = Legend)) +
theme_bw (base_family = "Times") +
scale_colour_manual (values = c("purple", "green", "blue", "yellow", "magenta","orange", "cyan", "red", "black")) +
geom_point (size = 3) +
geom_smooth (aes(group = 1, colour = "Trendline"), method = "loess", size = 1, linetype = 5, se = FALSE) +
geom_smooth (aes(group = 1, colour = "Regression (log)"),linetype = 1, size=1.2,method = "lm", formula = y~ log(x), se = FALSE) +
labs (title = "Correlation of LAI and NDVI")+
theme (legend.title = element_text (size = 15))
Which results in this plot:
As you can see, all Legend Icons look the same. What I want is that the points are shown as points and the two lines ("Regression" and "Trendline") are shown as lines.
I tried to use
guides (colour = guide_legend (override.aes = list(size = 1.5)))
but that gives me again all icons in the same way and I can not figure out how to distinguish between them
I´m new to R and this is my first "complex" plot. Try to figure out most with online helps and google but can´t find a solution for this problem. Thank you all for your time and help!
Here a dput of my data:
dput(NDVI2)
structure(list(MeanRED = c(3.240264, 6.97950484, 3.75052276,
4.62617908, 4.07743944, 4.88961572, 3.15865532, 2.28368236, 3.40793788,
4.28833416, 4.52529496, 2.45698208, 3.84003364, 4.31006672, 3.29672264,
4.21926652, 4.64357012, 3.94445908, 3.95942484, 1.22673756, 4.70933136,
5.33718396, 5.71857348, 5.7014266, 3.85938572, 6.07816804, 2.93602476,
5.00289296), MeanNIR = c(46.8226195806452, 48.4417953548387,
47.8913064516129, 43.9416386774194, 44.7524788709677, 52.2142607741935,
48.6422146774194, 44.6617992580645, 57.7213822580645, 58.5066447096774,
56.6924350967742, 57.4100250967742, 58.0419292903226, 58.7054423225806,
58.5283540645161, 54.7658463548387, 58.8950077096774, 58.2421209354839,
57.8538210645161, 50.209727516129, 59.5780209354839, 60.1662100645161,
62.1929408387097, 60.3309026451613, 57.859932516129, 63.5678422258065,
55.2536370967742, 60.1808743548387), NDVI = c(0.870552242769623,
0.748129155560663, 0.854748647859414, 0.809496111062421, 0.832994214160536,
0.828746627367857, 0.878046244390978, 0.902709173224405, 0.888500710549276,
0.863417928083076, 0.852157374806182, 0.917918660181389, 0.875891666709934,
0.863206160341016, 0.893353221193523, 0.856937918252258, 0.853834622095331,
0.873141147848366, 0.871890732089488, 0.952300860559358, 0.853491201866442,
0.837040994913869, 0.831587513918106, 0.827314084928549, 0.874937512911774,
0.825455384542418, 0.899087753174211, 0.846498808949291), LAI2 = c(1.1,
1.2, 1.3, 1.4, 2.1, 2.2, 2.3, 2.4, 3.1, 3.2, 3.3, 3.4, 4.1, 4.2,
4.3, 4.4, 5.1, 5.2, 5.3, 5.4, 6.1, 6.2, 6.3, 6.4, 7.1, 7.2, 7.3,
7.4), Legend = c("LAI 1", "LAI 1", "LAI 1", "LAI 1", "LAI 2",
"LAI 2", "LAI 2", "LAI 2", "LAI 3", "LAI 3", "LAI 3", "LAI 3",
"LAI 4", "LAI 4", "LAI 4", "LAI 4", "LAI 5", "LAI 5", "LAI 5",
"LAI 5", "LAI 6", "LAI 6", "LAI 6", "LAI 6", "LAI 7", "LAI 7",
"LAI 7", "LAI 7")), .Names = c("MeanRED", "MeanNIR", "NDVI",
"LAI2", "Legend"), class = "data.frame", row.names = c("LAI 1-1",
"LAI 1-2", "LAI 1-3", "LAI 1-4", "LAI 2-1", "LAI 2-2", "LAI 2-3",
"LAI 2-4", "LAI 3-1", "LAI 3-2", "LAI 3-3", "LAI 3-4", "LAI 4-1",
"LAI 4-2", "LAI 4-3", "LAI 4-4", "LAI 5-1", "LAI 5-2", "LAI 5-3",
"LAI 5-4", "LAI 6-1", "LAI 6-2", "LAI 6-3", "LAI 6-4", "LAI 7-1",
"LAI 7-2", "LAI 7-3", "LAI 7-4"))
override.aes is definitely a good start for customizing the legend. In your case you may remove unwanted shape in the legend by setting them to NA, and set unwanted linetype to blank:
ggplot(data = NDVI2, aes(x = LAI2, y = NDVI, colour = Legend)) +
geom_point(size = 3) +
geom_smooth(aes(group = 1, colour = "Trendline"),
method = "loess", se = FALSE, linetype = "dashed") +
geom_smooth(aes(group = 1, colour = "Regression (log)"),
method = "lm", formula = y ~ log(x), se = FALSE, linetype = "solid") +
scale_colour_manual(values = c("purple", "green", "blue", "yellow", "magenta","orange", "cyan", "red", "black"),
guide = guide_legend(override.aes = list(
linetype = c(rep("blank", 7), "solid", "dashed"),
shape = c(rep(16, 7), NA, NA))))

Resources