The library demonstrates extremely strange behavior when x or y axis has only one category. I prepared for you several examples to demonstrate it. Besides, please pay attention that I define x axis and y axis properties like plot$x$opts$yAxis$axisLabel$fontSize <- 10
. This is necessary measure because functions e_x_axis()
and e_y_axis()
are not sensitive to this properties.
library(data.table)
library(echarts4r)
dt_1 <- data.table(
user = rep("a", times = 3),
variable = c('anonymous', 'identified', 'unique'),
value = c(110, 550, 15)
)
dt_2 <- data.table(
user = rep("all", times = 3),
variable = c('anonymous', 'identified', 'unique'),
value = c(110, 550, 15)
)
dt_3 <- data.table(
user = rep(c("all", "not all"), each = 3),
variable = rep(c('anonymous', 'identified', 'unique'), times = 2),
value = c(110, 550, 15, 140, 88, 17)
)
{
plot <- dt_1 %>%
e_charts(variable) %>%
e_heatmap(user, value, label = list(normal = list(show = TRUE))) %>%
e_grid(left = '13%', right = '3%', bottom = '10%', top = '15%') %>%
e_visual_map(value,
orient = 'horizontal', calculable = TRUE, left = 'center',
type = 'continuous', splitNumber = 10)
plot$x$opts$xAxis$position <- 'top'
plot$x$opts$yAxis$axisLabel$fontSize <- 10
plot
}
{
plot <- dt_2 %>%
e_charts(variable) %>%
e_heatmap(user, value, label = list(normal = list(show = TRUE))) %>%
e_grid(left = '13%', right = '3%', bottom = '10%', top = '15%') %>%
e_visual_map(value,
orient = 'horizontal', calculable = TRUE, left = 'center',
type = 'continuous', splitNumber = 10)
plot$x$opts$xAxis$position <- 'top'
plot$x$opts$yAxis$axisLabel$fontSize <- 10
plot
}
{
plot <- dt_3 %>%
e_charts(variable) %>%
e_heatmap(user, value, label = list(normal = list(show = TRUE))) %>%
e_grid(left = '13%', right = '3%', bottom = '10%', top = '15%') %>%
e_visual_map(value,
orient = 'horizontal', calculable = TRUE, left = 'center',
type = 'continuous', splitNumber = 10)
plot$x$opts$xAxis$position <- 'top'
plot$x$opts$yAxis$axisLabel$fontSize <- 10
plot
}
{
plot <- dt_2[variable == "anonymous", ] %>%
group_by(user) %>%
e_charts(user) %>%
e_bar(value) %>%
e_grid(left = '13%', right = '3%', bottom = '10%', top = '15%')
plot
}
{
plot <- dt_3[variable == "anonymous", ] %>%
group_by(user) %>%
e_charts(user) %>%
e_bar(value) %>%
e_grid(left = '13%', right = '3%', bottom = '10%', top = '15%')
plot
}