You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create a stacked bar chart for two different companies, in different regions. See below a reproducible example:
library(dplyr)
library(echarts4r)
# Sample data for company X and Y total_X<-data.frame(
region=factor(c("A", "B", "C")),
Source_1= c(5, 3, 6),
Source_2= c(7, 9, 1),
Source_3= c(3, 4, 8),
company="X"
)
total_Y<-data.frame(
region=factor(c("A", "B", "C")),
Source_1= c(4, 7, 1),
Source_2= c(1, 5, 7),
Source_3= c(8, 3, 2),
company="Y"
)
# Merge data frames by regiontest<- left_join(total_X, total_Y, by="region")
# Define a custom color palette as a named listcustom_colors<-list(
Source_1="#1f77b4", # blueSource_2="#ff7f0e", # orangeSource_3="#2ca02c"# green
)
# Create the comparison chart with consistent colorsg_total_figure<-test %>%
e_charts(region) %>%
e_bar(Source_1.x, stack="grp", name="Source_1", itemStyle=list(color=custom_colors$Source_1)) %>%
e_bar(Source_2.x, stack="grp", name="Source_2", itemStyle=list(color=custom_colors$Source_2)) %>%
e_bar(Source_3.x, stack="grp", name="Source_3", itemStyle=list(color=custom_colors$Source_3)) %>%
e_bar(Source_1.y, stack="grp2", name="Source_1", itemStyle=list(color=custom_colors$Source_1)) %>%
e_bar(Source_2.y, stack="grp2", name="Source_2", itemStyle=list(color=custom_colors$Source_2)) %>%
e_bar(Source_3.y, stack="grp2", name="Source_3", itemStyle=list(color=custom_colors$Source_3)) %>%
e_tooltip(trigger='item', formatter= e_tooltip_item_formatter("decimal", digits=2)) %>%
e_toolbox_feature(feature="saveAsImage") %>%
e_legend(show=TRUE, textStyle=list(fontSize=20)) %>%
e_y_axis(
name="Source (kg)",
nameLocation="middle",
nameRotate=90,
nameTextStyle=list(fontSize=20),
nameGap=40,
axisLabel=list(fontSize=20)
)
# Print the chartg_total_figure
The figure below is what I get.
It works, but I can't identify the companies (X and Y) in this Figure. I tried to use e_facet but couldn't figure it out how. What I was looking for was something similar to facet_wrap for ggplot2 that shows the facet (regions A, B and C in this case) and below the bar the name of the company (X and Y) for each region.
Any suggestions?
The text was updated successfully, but these errors were encountered:
I am trying to create a stacked bar chart for two different companies, in different regions. See below a reproducible example:
The figure below is what I get.
![image](https://private-user-images.githubusercontent.com/95891986/341976026-905685f4-e6e8-4052-8ddd-d2f091dcb11f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ3MzE1MDQsIm5iZiI6MTcyNDczMTIwNCwicGF0aCI6Ii85NTg5MTk4Ni8zNDE5NzYwMjYtOTA1Njg1ZjQtZTZlOC00MDUyLThkZGQtZDJmMDkxZGNiMTFmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI3VDA0MDAwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVlZTg2Mzk4YzQ1Mjk5MjBmZTc0YTcxM2FjODI4OTM1NDkyYzIzODEwZGE2YzI3OWRiNTNlMWQ5ZjY3NDk5MzkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.k5NX-vkzdKyHd7OIbs82gKIUKQPzJctD9nYe3zhtsvc)
It works, but I can't identify the companies (X and Y) in this Figure. I tried to use e_facet but couldn't figure it out how. What I was looking for was something similar to facet_wrap for ggplot2 that shows the facet (regions A, B and C in this case) and below the bar the name of the company (X and Y) for each region.
Any suggestions?
The text was updated successfully, but these errors were encountered: