This is probably an easy question for ggplot2 experts: I want to use my own colors rather than the default colors. How to achieve that?
Here's a snippet of the data:
df <- structure(list(start = c(0, 251, 1976, 5127, 5717, 6783), end = c(251,
1976, 5127, 5717, 6783, 6830), minute = c(0L, 0L, 0L, 0L, 0L,
0L), AOI = c("*", "A", "*", "*", "A", "*"), AOI_col = c("blue",
"red", "blue", "blue", "red", "blue")), row.names = c(NA, -6L
), groups = structure(list(minute = 0L, .rows = structure(list(
1:6), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr",
"list"))), row.names = 1L, class = c("tbl_df", "tbl", "data.frame"
), .drop = TRUE), class = c("grouped_df", "tbl_df", "tbl", "data.frame"
))
The colors I wish to plot are in column AOI_col. Here's the code so far:
library(ggplot2)
ggplot(df5, aes(x = start, xend = end,
y = minute + scale(as.numeric(as.factor(AOI)))/10,
yend = minute + scale(as.numeric(as.factor(AOI)))/10,
color = AOI)) +
geom_segment(size = 2) +
scale_y_reverse(breaks = 0:53, labels = paste0(0:53, "min"), name = NULL) +
labs(title = "Gaze activity Speaker C F01") +
theme(axis.title.x.bottom = element_blank())
I've tried using aes(fill = AOI_col) and scale_color_manual(values = AOI_col) but to no avail. Help is appreciated!
You can add a color adjustment in the geom_segment():
ggplot(df, aes(x = start, xend = end,
y = minute + scale(as.numeric(as.factor(AOI)))/10,
yend = minute + scale(as.numeric(as.factor(AOI)))/10)) +
geom_segment(size = 2, color = df$AOI_col) +
scale_y_reverse(breaks = 0:53, labels = paste0(0:53, "min"), name = NULL) +
labs(title = "Gaze activity Speaker C F01") +
theme(axis.title.x.bottom = element_blank())
Or again the complete example with the answer from #user438383:
df <-
structure(
list(
start = c(0, 251, 1976, 5127, 5717, 6783),
end = c(251,
1976, 5127, 5717, 6783, 6830),
minute = c(0L, 0L, 0L, 0L, 0L,
0L),
AOI = c("*", "A", "*", "*", "A", "*"),
AOI_col = c("blue",
"red", "blue", "blue", "red", "blue")
),
row.names = c(NA,-6L),
groups = structure(
list(
minute = 0L,
.rows = structure(
list(1:6),
ptype = integer(0),
class = c("vctrs_list_of", "vctrs_vctr",
"list")
)
),
row.names = 1L,
class = c("tbl_df", "tbl", "data.frame"),
.drop = TRUE
),
class = c("grouped_df", "tbl_df", "tbl", "data.frame")
)
library(ggplot2)
ggplot(df,
aes(
x = start,
xend = end,
y = minute + scale(as.numeric(as.factor(AOI))) / 10,
yend = minute + scale(as.numeric(as.factor(AOI))) / 10,
color = AOI
)) +
geom_segment(size = 2) +
scale_y_reverse(breaks = 0:53,
labels = paste0(0:53, "min"),
name = NULL) +
labs(title = "Gaze activity Speaker C F01") +
theme(axis.title.x.bottom = element_blank()) +
scale_colour_manual(values = unique(df$AOI_col))
I think the ideal thing to do is make AOI_col a factor and sort it alphabetically, then assign the colours to be the unique values of that column:
df5$AOI_col = factor(df5$AOI_col, levels = sort(unique(df$AOI_col)))
ggplot(df5, aes(x = start, xend = end,
y = minute + scale(as.numeric(as.factor(AOI)))/10,
yend = minute + scale(as.numeric(as.factor(AOI)))/10,
color = AOI)) +
geom_segment(size = 2) +
scale_y_reverse(breaks = 0:53, labels = paste0(0:53, "min"), name = NULL) +
labs(title = "Gaze activity Speaker C F01") +
theme(axis.title.x.bottom = element_blank()) +
scale_colour_manual(values = unique(df$AOI_col))
Related
i have three variables in my dataset:
school (School)
actual score (actual_score)
expected score (expected_score)
and need to do this graph
So far I have
data%>%
mutate(School=fct_reorder(School, actual_score)
)%>%
ggplot(aes(x=School))+
geom_point(aes(y=actual_score), colour="red")+
geom_point(aes(y= expected_score), colour="blue")
But they are just points... how to connect them?
structure(list(School = structure(c(9L,
6L, 8L, 2L, 1L), levels = c("11278", "11274", "11285", "11289",
"11280", "01424", "11290", "11272", "01206", "11286"), class = "factor"),
actual_score = c(453.4875, 423.375757575758, 441.481481481482,
375.103846153846, 363.621428571429), expected_score = c(452.489150512886,
428.002515274828, 439.209772701724, 384.917346549729, 382.216349569884
)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -5L), .rows = structure(list(
1:5), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -1L), .drop = TRUE))
Your dput result is slightly corrupt, so I slightly modified it.
You can use geom_linerange to connect the points.
I also included the rest of the graph as placing the labels is a bit tricky.
library(tidyverse)
data <- tibble(
School = structure(
c(9L, 6L, 8L, 2L, 1L),
levels = c("11278", "11274", "11285", "11289", "11280", "01424", "11290", "11272", "01206", "11286"),
class = "factor"),
actual_score = c(453.4875, 423.375757575758, 441.481481481482, 375.103846153846, 363.621428571429),
expected_score = c(452.489150512886, 428.002515274828, 439.209772701724, 384.917346549729, 382.216349569884))
data%>%
mutate(School = fct_reorder(fct_relabel(School, ~ paste("School", LETTERS[1:(length(.))])), actual_score)) %>%
ggplot(aes(x = School)) +
geom_linerange(aes(ymin = actual_score, ymax = expected_score)) +
geom_point(aes(y = actual_score, color = "Actual", shape = "Acutal"), size = 3) +
geom_text(aes(y = actual_score - 5 + 10 * (actual_score > expected_score), label = round(actual_score))) +
geom_point(aes(y = expected_score, color = "Expected", shape = "Expected"), size = 3) +
geom_text(aes(y = expected_score - 5 + 10 * (actual_score < expected_score), label = round(expected_score))) +
scale_color_manual(name = NULL,
labels = c("Acutal", "Expected"),
values = c("blue", "red")) +
scale_shape_manual(name = NULL,
labels = c("Acutal", "Expected"),
values = c(16, 17)) +
labs(y = "Average NAPLAN score", x = NULL) +
theme_minimal() +
theme(legend.position = "bottom",
panel.grid.major.x = element_blank())
Created on 2022-12-19 with reprex v2.0.2
To connect your points you could use a geom_segment. And to get the different shapes map on the shape aesthetic. Also do the same for color to get a legend reflecting both shape and color. The rest is some styling plus some additional geom_text layers for the labels.
library(dplyr)
library(ggplot2)
library(forcats)
data %>%
mutate(School = fct_reorder(School, actual_score)) %>%
ggplot(aes(x = School)) +
geom_segment(aes(xend = School, y = actual_score, yend = expected_score),
colour = "grey80", linewidth = 1
) +
geom_point(aes(y = actual_score, colour = "Actual", shape = "Actual"), size = 3) +
geom_point(aes(y = expected_score, colour = "Expected", shape = "Expected"), size = 3) +
geom_label(aes(
y = actual_score, label = round(actual_score),
vjust = ifelse(actual_score > expected_score, 0, 1)
), label.size = NA, label.padding = unit(10, "pt"), fill = NA) +
geom_label(aes(
y = expected_score, label = round(expected_score),
vjust = ifelse(expected_score > actual_score, 0, 1)
), label.size = NA, label.padding = unit(10, "pt"), fill = NA) +
scale_color_manual(values = c("red", "blue")) +
scale_shape_manual(values = c(16, 17)) +
scale_y_continuous(breaks = seq(320, 480, 40), limits = c(320, 480)) +
labs(color = NULL, shape = NULL, x = NULL, y = "Average NAPLAN Score") +
theme_minimal() +
theme(
legend.position = "bottom",
axis.title.y = element_text(face = "bold"),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank()
)
DATA
data <- structure(list(
School = structure(c(9L, 6L, 8L, 2L, 1L), levels = c(
"11278", "11274", "11285", "11289",
"11280", "01424", "11290", "11272", "01206", "11286"
), class = "factor"),
actual_score = c(
453.4875, 423.375757575758, 441.481481481482,
375.103846153846, 363.621428571429
), expected_score = c(
452.489150512886,
428.002515274828, 439.209772701724, 384.917346549729, 382.216349569884
)
), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -5L), .rows = structure(list(1:5), ptype = integer(0), class = c(
"vctrs_list_of",
"vctrs_vctr", "list"
)))
For a Difference in Difference method, I have come up with the following data:
df <- structure(list(Class = structure(c(1L, 1L, 2L, 2L), levels = c("PovCon",
"PovDeCon"), class = "factor"), After_2015 = structure(c(1L,
2L, 1L, 2L), levels = c("Before 2015", "After 2015"), class = "factor"),
mean_VLP = c(16.5314094033954, 25.3785125225305, 22.4646340695607,
19.5147929056452), se_duration = c(3.72103200892531, 8.17273164333138,
4.03966402631034, 2.56248212580638), upper = c(23.824632140889,
41.39706654346, 30.382375561129, 24.5372578722257), lower = c(9.23818666590181,
9.35995850160102, 14.5468925779924, 14.4923279390647)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -4L), groups = structure(list(
Class = structure(1:2, levels = c("PovCon", "PovDeCon"), class = "factor"),
.rows = structure(list(1:2, 3:4), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L), .drop = TRUE))
For the graphical presentation, I used the following codes:
ggplot(df, aes(x = After_2015,
y = mean_VLP,
color = Class)) +
geom_pointrange(aes(ymin = lower, ymax = upper), size = 1) +
geom_line(aes(group = Class))
Now, as per the requirement of a journal, I would need to have everything in black and white, no color!
Hence, I would ideally like to get two different shapes for the two Class and different linetypes which connect the two corresponding data points.
I used the following code to change the lines:
ggplot(plot_data_VLP, aes(x = After_2015,
y = mean_VLP,
shape = Class,
linetype = Class)) +
geom_pointrange(aes(ymin = lower, ymax = upper), size = 1) +
geom_line(aes(group = Class)))
How do I change the shape with upward and downward triangles?
Please help, and thank you for your time.
To get different shapes you have to map on the shape aesthetic:
library(ggplot2)
base <- ggplot(df, aes(
x = After_2015,
y = mean_VLP,
linetype = Class
)) +
geom_pointrange(aes(ymin = lower, ymax = upper, shape = Class), size = 1) +
geom_line(aes(group = Class))
base
UPDATE: To get upward and downward triangles you could use a manual scale where for the shapes I use some UTF8 (https://www.compart.com/en/unicode/block/U+25A0):
base + scale_shape_manual(values = c("\u25B2", "\u25BC"))
I am trying to display all month values on my x-axis, which is formatted as a "yearmon" variable
My data are structured as follows:
Print data example
dput(collective_action_monthly[1:4, ])
ouptut:
structure(list(collective_action = structure(c(2L, 2L, 2L, 2L
), .Label = c("0", "1"), class = "factor"), treatment_details = c("pre",
"pre", "pre", "pre"), month_year = structure(c(2011.41666666667,
2011.75, 2011.83333333333, 2011.91666666667), class = "yearmon"),
n = c(22L, 55L, 15L, 207L), collective_action_percentage = c(0.0124223602484472,
0.031055900621118, 0.00846979107848673, 0.116883116883117
), am = structure(c(2L, 2L, 2L, 2L), .Label = c("post", "pre"
), class = "factor")), class = c("grouped_df", "tbl_df",
"tbl", "data.frame"), row.names = c(NA, -4L), groups = structure(list(
treatment_details = "pre", .rows = structure(list(1:4), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -1L), .drop = TRUE))
This my code to visualize the trend using bar graphs by month:
ggplot(data = collective_action_monthly, aes(x = month_year, y = collective_action_percentage)) +
geom_bar(stat = "identity", position=position_dodge()) +
scale_fill_grey() +
ylab("percentage") +
theme(text=element_text(size=10)) +
theme(plot.title = element_text(size = 10, face = "bold")) +
scale_y_continuous(labels = percent_format(accuracy = 1)) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) +
theme_bw()
which produces:
However, rather than only showing three months in the x-axis, I would like to show all months. I also tried adding "scale_x_continuous(labels = 0:14, breaks = 0:14) " to the code above, but it still does not display months:
Ideally, I would like to produce a graph as the one below, but with months instead of years.
The zoo packages includes scale_x_yearmon, so you can do:
library(zoo)
library(ggplot2)
ggplot(data = collective_action_monthly,
aes(x = month_year, y = collective_action_percentage)) +
geom_col(position = position_dodge(preserve = "single")) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1),
name = "percentage") +
scale_x_yearmon(breaks = seq(2011.25, 2012, 1/12),
limits = c(2011.25, 2012)) +
theme_bw(base_size = 10) +
theme(plot.title = element_text(size = 10, face = "bold"),
axis.text.x = element_text(angle = 90, vjust = 0.5))
ggplot doesn't have a yearmon scale built in--looks like the zoo package does, but it doesn't have a convenient way to specify "breaks every month"--so I would suggest converting to Date class and using scale_x_date. I've deleted most of your theme stuff to make the changes I've made more obvious (the theming didn't seem relevant to the issue).
ggplot(data = collective_action_monthly, aes(x = as.Date(month_year), y = collective_action_percentage)) +
geom_bar(stat = "identity", position=position_dodge()) +
scale_fill_grey() +
scale_x_date(date_breaks = "1 month", date_labels = "%b %Y") +
ylab("percentage") +
theme_bw()
I'm trying to place count labels in a ggplot2 barplot and I haven't been able to do it. I need to display the number of pixels within each temperature range.
The dataframe was built from a raster: EneroT5cmSC
datene <- as.data.frame(EneroT5cmSC,xy=TRUE)%>%drop_na()
datene$cuts <- cut(datene$layer, breaks=seq(21, 29, length.out=12))
dput:
datene_stuc <- structure(
list(
x = c(-57.063098328,-57.021448328,-56.996458328,-56.988128328),
y = c(-30.087481664,-30.087481664,-30.087481664,-30.087481664),
layer = c(
25.6227328470624,
26.6386584334308,
26.0636709134397,
26.0580615984563
),
cuts = structure(
c(7L, 9L,
8L, 8L),
.Label = c(
"(20,20.8]",
"(20.8,21.6]",
"(21.6,22.5]",
"(22.5,23.3]",
"(23.3,24.1]",
"(24.1,24.9]",
"(24.9,25.7]",
"(25.7,26.5]",
"(26.5,27.4]",
"(27.4,28.2]",
"(28.2,29]"
),
class = "factor"
)
),
row.names = c(NA,
4L),
class = "data.frame")
Barplot code:
ggplot() +
geom_bar(data = datene, aes(cuts, fill = cuts)) +
scale_fill_viridis_d(option = "B",'Temp (Cº)') +
theme(axis.title.x=element_blank(), axis.title.y=element_blank()) +
geom_text(aes(label = ..count..), stat = "count", vjust = 1.5, colour = "black")
If you replace the code arguments from geom_bar to ggplot() and change vjust = -1 it works like this:
datene_stuc <- structure(
list(
x = c(-57.063098328,-57.021448328,-56.996458328,-56.988128328),
y = c(-30.087481664,-30.087481664,-30.087481664,-30.087481664),
layer = c(
25.6227328470624,
26.6386584334308,
26.0636709134397,
26.0580615984563
),
cuts = structure(
c(7L, 9L,
8L, 8L),
.Label = c(
"(20,20.8]",
"(20.8,21.6]",
"(21.6,22.5]",
"(22.5,23.3]",
"(23.3,24.1]",
"(24.1,24.9]",
"(24.9,25.7]",
"(25.7,26.5]",
"(26.5,27.4]",
"(27.4,28.2]",
"(28.2,29]"
),
class = "factor"
)
),
row.names = c(NA,
4L),
class = "data.frame")
library(ggplot2)
ggplot(data = datene_stuc, aes(cuts, fill = cuts)) +
geom_bar() +
geom_text(aes(label = ..count..), stat = "count", vjust = -1, colour = "black") +
scale_fill_viridis_d(option = "B",'Temp (Cº)') +
theme(axis.title.x=element_blank(), axis.title.y=element_blank())
Created on 2022-07-17 by the reprex package (v2.0.1)
I am attempting to make a series of plots using the same code with unique coral species databases.
Databases
data_1 <- structure(list(Site_long = structure(c(1L, 1L, 2L, 2L), .Label = c("Hanauma Bay",
"Waikiki"), class = "factor"), Shelter = structure(c(1L, 2L,
1L, 2L), .Label = c("Low", "High"), class = c("ordered", "factor"
)), mean = c(1.19986885018767, 2.15593884020962, 0.369605100791602,
0.31005865611133), sd = c(2.5618758944073, 3.67786619671933,
1.0285671157698, 0.674643037178562), lower = c(0.631321215232725,
1.33972360808602, 0.141339007832154, 0.160337623931733), upper = c(1.76841648514261,
2.97215407233321, 0.59787119375105, 0.459779688290928), sample_size = c(78L,
78L, 78L, 78L)), row.names = c(NA, -4L), groups = structure(list(
Site_long = structure(1:2, .Label = c("Hanauma Bay", "Waikiki"
), class = "factor"), .rows = structure(list(1:2, 3:4), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = 1:2, class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
data_2 <- structure(list(Site_long = structure(c(2L, 2L, 1L, 1L), .Label = c("Hanauma Bay",
"Waikiki"), class = "factor"), Shelter = structure(c(1L, 2L,
1L, 2L), .Label = c("Low", "High"), class = c("ordered", "factor"
)), mean = c(0.695203162997812, 0.838720069947102, 0.76957780057238,
0.771070502382599), sd = c(1.17117437618039, 1.02766824928792,
1.43499288333539, 1.28634022958585), lower = c(0.435288768568787,
0.610653459098997, 0.451115141323908, 0.485597776371556), upper = c(0.955117557426838,
1.06678668079521, 1.08804045982085, 1.05654322839364), sample_size = c(78L,
78L, 78L, 78L)), row.names = c(NA, -4L), groups = structure(list(
Site_long = structure(1:2, .Label = c("Hanauma Bay", "Waikiki"
), class = "factor"), .rows = structure(list(3:4, 1:2), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = 1:2, class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
When I run my code on the first species database (data_1), the barplots and associated error bar annotations render correctly. Notice I also made a new variable "data" that will be the same object used in later for species 2. In order to keep this plot to make a composite of a number of plots later, I named the plot "species_1_plot" to save it to the global environment.
Code for Species 1 Plot
data <- data_1
mult_compare_recruitment <- c("A", "A", "A", "A")
data <- data[c(3, 4, 1, 2),]
data$Shelter <- factor(data$Shelter, levels = c("Low", "High"))
# reorder summary dataframe for plotting
position <- c("Waikiki", "Hanauma Bay")
# ggplot2 barplot position with Waikiki (Low-High Shelter) and Hanauma Bay
recruitment_plot_3 <- ggplot(data = data, aes(fill=Shelter, y=mean, x=Site_long)) +
geom_bar(position = "dodge", stat="identity", width = .8) +
scale_x_discrete(limits = position) +
geom_errorbar(aes(ymin = lower, ymax = upper), position = position_dodge(.8), width = .1) +
geom_text(aes(label = mult_compare_recruitment, y = data$upper), vjust = -.5, position = position_dodge(width = 0.8), size = 4) +
scale_fill_grey(name = "Shelter", start = .8, end = .2) +
labs(x = "Site", y = expression(paste("Coral recruitment per m"^"2"))) +
theme_classic(base_size = 14.5) +
theme(text = element_text(size = 18), axis.title.x = element_blank(),
legend.position = "none", axis.text.y = element_text(angle = 90))
species_1_plot <- recruitment_plot_3
species_1_plot
In order to create my next plot, I run the same code on a different species database (data_2) while once again assigning the new database to the object "data". Once again, I saved the new plot "species_2_plot" to the global environment.
Code for Species 2 Plot
data <- data_2
mult_compare_recruitment <- c("A", "A", "B", "B")
data <- data[c(3, 4, 1, 2),]
data$Shelter <- factor(data$Shelter, levels = c("Low", "High"))
# reorder summary dataframe for plotting
position <- c("Waikiki", "Hanauma Bay")
# ggplot2 barplot position with Waikiki (Low-High Shelter) and Hanauma Bay
recruitment_plot_3 <- ggplot(data = data, aes(fill=Shelter, y=mean, x=Site_long)) +
geom_bar(position = "dodge", stat="identity", width = .8) +
scale_x_discrete(limits = position) +
geom_errorbar(aes(ymin = lower, ymax = upper), position = position_dodge(.8), width = .1) +
geom_text(aes(label = mult_compare_recruitment, y = data$upper), vjust = -.5, position = position_dodge(width = 0.8), size = 4) +
scale_fill_grey(name = "Shelter", start = .8, end = .2) +
labs(x = "Site", y = expression(paste("Coral recruitment per m"^"2"))) +
theme_classic(base_size = 14.5) +
theme(text = element_text(size = 18), axis.title.x = element_blank(),
legend.position = "none", axis.text.y = element_text(angle = 90))
species_2_plot <- recruitment_plot_3
species_2_plot
The problem is, when I plot the first species plot again (species_1_plot), the data are correct (bars), but the height of text annotations and their letter values are not correct. They are in fact the values from species_2_plot.
species_1_plot
I saved each plot to the global environment with a unique name knowing this would be an issue. But despite this, geom_text() seems to be using data from the second plot (code that is in the global environment) instead despite that the actual data (bars) in the plot are correct (from species_plot_1). My understanding was that when you name a plot as an object (species_1_plot and species_2_plot) that its akin to saving the plot and therefore preventing any changes to plot and annotations unless specified. Is there any way to prevent this from happening without specifically naming the databases (data_1 and data_2)? All input is appreciated. Thanks in advance!
I would suggest you to use an approach with a function. The fact of using data twice is maybe changing the environment and as a result the plots change. I have made a function with parameters for data, position and recruitment and I display the outputs. You have to fill them in the same way you defined that variables in your code. Functions work on internal environments so there might not be issues about how data is processed. Here the code where I used the data you shared:
library(ggplot2)
#Function
myplotfunc <- function(x,y,z)
{
data <- x
mult_compare_recruitment <- y
data <- data[c(3, 4, 1, 2),]
data$Shelter <- factor(data$Shelter, levels = c("Low", "High"))
# reorder summary dataframe for plotting
position <- z
# ggplot2 barplot position with Waikiki (Low-High Shelter) and Hanauma Bay
plot <- ggplot(data = data, aes(fill=Shelter, y=mean, x=Site_long)) +
geom_bar(position = "dodge", stat="identity", width = .8) +
scale_x_discrete(limits = position) +
geom_errorbar(aes(ymin = lower, ymax = upper), position = position_dodge(.8), width = .1) +
geom_text(aes(label = mult_compare_recruitment, y = data$upper), vjust = -.5, position = position_dodge(width = 0.8), size = 4) +
scale_fill_grey(name = "Shelter", start = .8, end = .2) +
labs(x = "Site", y = expression(paste("Coral recruitment per m"^"2"))) +
theme_classic(base_size = 14.5) +
theme(text = element_text(size = 18), axis.title.x = element_blank(),
legend.position = "none", axis.text.y = element_text(angle = 90))
return(plot)
}
#Code
o1 <- myplotfunc(x=data_1,y=c("A", "A", "A", "A"),z=c("Waikiki", "Hanauma Bay"))
o2 <- myplotfunc(x=data_2,y=c("A", "A", "B", "B"),z=c("Waikiki", "Hanauma Bay"))
Outputs: