Comments (4)
Hi Victor,
Please find below reproducible examples:
title: "Apex markers"
author: "Miguel Eersel"
date: "2/11/2021"
output: html_document
knitr::opts_chunk$set(echo = TRUE, fig.width = 15, fig.height = 8.5)
library(tidyverse)
library(apexcharter)
x <- seq(0,2*pi, 0.4)
test_tbl <- tribble( ~x, ~y,
x, sin(x)) %>%
unnest() %>%
mutate(level = case_when(
y > 0.8 ~ "high",
y < -0.8 ~ "low",
TRUE ~ "normal"
))
test_tbl
test_tbl %>%
ggplot(aes(x=x, y = y)) +
geom_point(aes(col = level), size = 6) +
geom_line(color = "black") +
theme_minimal(base_size = 15)
I want to reproduce the above ggplot using apexcharter.
- Points are colored using the level category
- The line needs to have the color black
1st try-out
- line color is automatically set to red by apexcharter
test_tbl %>%
apexcharter::apex(mapping = aes(x=x,y=y, fill = level),type = "scatter") %>%
apexcharter::add_line(mapping = aes(x=x, y =y)) %>%
ax_stroke(width = 2)
2nd try-out
- set line color to black: colors = "#000000"
= chart is not displayed anymore
test_tbl %>%
apexcharter::apex(mapping = aes(x=x,y=y, fill = level),type = "scatter") %>%
apexcharter::add_line(mapping = aes(x=x, y =y)) %>%
ax_stroke(width = 2, colors = "#000000")
EMPTY NO CHART
3rd try-out
- use ax_coolors() function
- line and markers are all turned to black
test_tbl %>%
apexcharter::apex(mapping = aes(x=x,y=y, fill = level),type = "scatter") %>%
apexcharter::add_line(mapping = aes(x=x, y =y)) %>%
ax_colors("black")
4th try-out
- first create a line chart
- second add the markers to the line chart
- Question: how to color markers according to the levels ?
test_tbl %>%
apexcharter::apex(mapping = aes(x=x,y=y),type = "line") %>%
ax_stroke(width = 2,colors = "#000000") %>%
ax_markers(size = 6)
from apexcharter.
Hi,
Can you share a reproducible example please ? I'll look into it.
Victor
from apexcharter.
from apexcharter.
Thanks for the detailed example and the different tries.
There's a little bug in add_line
causing incorrect markers size. You can obtain a correct a chart by specifying explicit markers size (three for the scatter, one for the line):
test_tbl %>%
apex(mapping = aes(x = x, y = y, fill = level),type = "scatter") %>%
add_line(mapping = aes(x = x, y = y)) %>%
ax_markers(size = c(6, 6, 6, 0))
For coloring the line, you can use ax_colors_manual
like this:
test_tbl %>%
apex(mapping = aes(x = x, y = y, fill = level),type = "scatter") %>%
add_line(mapping = aes(x = x, y = y)) %>%
ax_markers(size = c(6, 6, 6, 0)) %>%
ax_colors_manual(
list(
normal = "#01DFD7",
high = "#F7D358",
low = "#FA58F4",
y = "#848484"
)
)
You can change the name "y" using serie_name
in add_line()
.
Or use ax_stroke
, but putting the color in a list
because JavaScript expect an array and in JS character and vector of length one are not the same thing.. :
test_tbl %>%
apex(mapping = aes(x = x, y = y, fill = level),type = "scatter") %>%
add_line(mapping = aes(x = x, y = y)) %>%
ax_markers(size = c(6, 6, 6, 0)) %>%
ax_stroke(width = 2, colors = list("#000000"))
But note that it doesn't affect the legend..
Hope it helps,
Victor
from apexcharter.
Related Issues (20)
- Adding Icons or Color to the Tooltip HOT 2
- Adding Confidence Intervals HOT 4
- Creating box plot with apexcharter HOT 2
- facet not working on shinyapps HOT 3
- Brush does not work HOT 3
- Combining facets with annotations HOT 1
- Mixed/Combo charts when using apex() function to create series
- Stacked Bar Chart by Week Ending Date - x-axis labels HOT 3
- Colour mis-match on line markers for more than 10 series HOT 1
- No shared tooltip HOT 4
- Thrid y axis HOT 2
- Change to new cran checks badge URL HOT 1
- Feature request: New chart type - box plots HOT 5
- Adding Icons to the Labels in a Legend HOT 4
- Format numbers in spark_box's tooltip HOT 2
- ax_forecast_data_points() seems to be missing HOT 2
- Remove Time Gaps from Candlestick Chart HOT 2
- [Feature request] - adding outliers and custom data points to a boxplot
- Synchronize Charts Example doesn't display both plots at the same time in Rstudio's plot panel. HOT 2
- Feature request: bring crosstalk functionality to connect apexchart with tables
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apexcharter.