Description Usage Arguments Value Examples
This function use the given x_var
and bar_var
to draw bar plot but
use the given x_var
and the first column in dataset
except x_var
and
bar_var
to draw line plot. The principle of drawing bar and line plot in one figure is
to map the graduation of line plot to the main Y axis and write the actual graduation of line
plot to the secondary Y axis.
You can control the top and bottom blank of line plot using
parameters scale_blank_div
and specify the range of line plot in the main Y axis using
parameters scale_interval
. These two parameters can easily control the scope of line plot
to make it not conflict with bar plot.
This function has the auto-detect function to change variable name in English to axis name in
Chinese. The information in option
you have set before run r plot code is used as a
convertor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | bar_line_ggplot(
dataset,
x_var,
bar_var = "sample_size",
scale_blank_div = 5,
scale_interval = NA,
main_axis_name,
sec_axis_name,
x_axis_name,
bar_fill_palette = "grey",
line_color = "black",
point_color = "white",
legend_pos = c("none", "left", "right", "bottom", "top"),
label_size = 4
)
|
dataset |
data frame containing at least 3 columns. |
x_var |
character. The column name that will be the X axis in the plot. |
bar_var |
character, default |
scale_blank_div |
numeric, default 5. It directly affect the proportion of the figure height that line plot occupied. The line plot in the figure will occupies \frac{scale_blank_div-2}{scale_blank_div} of the figure height and leave blanks in the top and bottom \frac{1}{scale_blank_div}. |
scale_interval |
numeric vector of length 2. The interval of line plot in the main Y axis. |
main_axis_name |
character. The name of main Y axis. If missing, the function will use
information in |
sec_axis_name |
character. The name of secondary Y axis. If missing, the function will use
information in |
x_axis_name |
character. The name of X axis. If missing, the function will use
information in |
bar_fill_palette |
character of character vector. It is the color palette of bar plot. |
line_color |
character of color. It is the color of line in line plot. |
point_color |
character of color. It is the color of point in line plot. |
legend_pos |
character of character vector. It controls the position of legend. |
label_size |
numeric, default 4. It controls the size of lebel of line plot. DO NOT make it less than 4 of larger than 6 or it will look ugly. |
an object of class ggplot
.
1 2 | df <- data.frame(year = as.factor(2016:2020), sample_size = 10:14, qualification_rate = 81:85)
bar_line_ggplot(df, x_var = "year", bar_var = "sample_size")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.