af_create_y_plot(data, y_var = "mpg", group_var = "cyl", subgroup_var = "am", plot_types = c("density"))
af_create_y_plot(data, y_var = "mpg", group_var = "cyl", subgroup_var = "am", plot_types = c("density"),
use_facet = TRUE)
af_create_y_plot(data, y_var = "mpg", group_var = "cyl", plot_types = c("histogram dodged"), bins = 10)
af_create_y_plot(data, y_var = "mpg", group_var = "cyl", subgroup_var = "am",
plot_types = c("histogram dodged"), bins = 10)
af_create_y_plot(data, y_var = "mpg", group_var = "cyl", subgroup_var = "am", plot_types = c("histogram dodged"),
bins = 10, use_facet = TRUE, facet_cols = 2)
af_create_y_plot(data, y_var = "mpg", group_var = "cyl", plot_types = c("density", "histogram"), bins = 10)
# Basic usage - plotting horsepower vs mpg
af_create_xy_plot(
data = mtcars,
y_var = "hp",
grouping_variable = "None",
show_points = TRUE
)
# Basic usage - plotting horsepower vs mpg
af_create_xy_plot(
data = mtcars,
x_var = "mpg",
y_var = "hp",
grouping_variable = "None",
show_points = TRUE
)
# Plotting horsepower, displacement and weight against mpg
af_create_x_multi_y_plot(
data = mtcars,
y_var_names = c("hp", "disp", "wt"),
show_points = TRUE
)
# Plotting horsepower, displacement and weight against mpg
af_create_x_multi_y_plot(
data = mtcars,
x_var = "mpg",
y_var_names = c("hp", "disp", "wt"),
show_points = TRUE
)
Add trend lines to see relationships more clearly (note that connecting lines are removed when smoothing is enabled):
# Adding smoothed trend lines
af_create_x_multi_y_plot(
data = mtcars,
x_var = "mpg",
y_var_names = c("hp", "disp", "wt"),
smooth = TRUE,
show_points = TRUE
)
af_combine_plots(
af_plot_correlation_per_group(mtcars, group_var = "cyl", group_values = NULL, vars = NULL)
)
Create example dataset (HDI vs Extremism data)
set.seed(123)
countries <- c("USA", "FRA", "GER", "JPN", "RUS", "CHN", "BRA", "IND", "MEX", "CAN",
"ARG", "ESP", "ITA", "AUS", "NED", "SWE", "POL", "TUR", "EGY", "SAF",
"NOR", "FIN", "DEN", "GRE", "POR", "CZE", "HUN", "AUT", "BEL", "IRE",
"MAL", "ETH", "PAK", "BAN", "VIE", "NIC", "HOK", "TAJ", "ALB", "ARM")
regions <- c(rep("West", 10),
rep("Latin/Central America", 5),
rep("Ex-communist countries", 8),
rep("Arab countries", 5),
rep("Asia", 7),
rep("Sub-Saharan Africa", 5))
# Create sample data frame
df <- data.frame(
country_code = countries,
region = regions,
HDI = runif(40, min = 40, max = 95),
total_extremism = rnorm(40, mean = 0, sd = 20)
)
Example 1: With coloring by region and a linear trend line
af_scatter_map(df,
identity_var_name = "country_code",
x_var_name = "HDI",
y_var_name = "total_extremism",
color_var_name = "region",
line_type = "linear")
Example 2: With coloring by region and a smooth trend line
af_scatter_map(df,
identity_var_name = "country_code",
x_var_name = "HDI",
y_var_name = "total_extremism",
color_var_name = "region",
line_type = "smooth")