

- #PLOT LINE GRAPH R INSTALL#
- #PLOT LINE GRAPH R FULL#
- #PLOT LINE GRAPH R CODE#
- #PLOT LINE GRAPH R SERIES#

#PLOT LINE GRAPH R CODE#
In the code below, I first save my chart in a variable called p so I don’t have to keep repeating that code. There are 13 built-in themes, which you can see on the echarts4r website. You’ll probably want to customize the colors for your charts at some point. I can turn this line chart into a grouped bar chart just by swapping in e_bar() for e_line(). I can do that with this function: e_tooltip(trigger = "axis")
#PLOT LINE GRAPH R SERIES#
Screen shot by Sharon Machlis, IDGĮcharts4r line chart with two series and tooltips.īut the tooltip here could be even more useful if I could see both values at the same time. Notice that commas are added to the tooltip values by default, which is nice. There are no tooltips displayed by default, but I can add those with the e_tooltips() function.

John Coene calls those “escape-hatch” functions, and they have an underscore at the end of the function name, such as: e_line(Boston) my_city % e_charts(x = Month) %>% e_line(serie = `San Francisco`) %>% e_line(serie = Boston) That lets you use variable names as arguments. That’s similar to how ggplot works.īut most functions listed here have versions that take quoted column names.
#PLOT LINE GRAPH R FULL#
You can see the full list on the echarts4r package website or in the help files.Įach of the chart-type functions take column names without quotation marks as arguments. There are many other chart types available, including bar charts with e_bar(), area charts e_area(), scatter plots e_scatter(), box plots e_boxplot(), histograms e_histogram(), heat maps e_heatmap(), tree maps e_tree(), word clouds e_cloud(), and pie charts e_pie(). Line chart of Zillow data created with echarts4r. houses_wide %>% e_charts(x = Month) %>% e_line(serie = `San Francisco`) Screen shot by Sharon Machlis, IDG The argument is called serie, as in singular of series. It needs at least one argument, the column with the values. For a line chart, that’s the e_line() function. Next, I’ll add the type of chart I want and the y-axis column. You’ll see the x axis but no y axis or data.ĭepending on your browser width, all the axis labels may not display because echarts4r is responsive by default - you don’t have to worry about the axis text labels overwriting each other if there's not enough room for them all. If you’re familiar with ggplot, this first step is similar: It creates an object, but there’s no data in the visualization yet. In the code below, I create a basic echarts4r object with Month as the x-axis column.
#PLOT LINE GRAPH R INSTALL#
You can install the dev version with these lines: remotes::install_github"JohnCoene/echarts4r") library(echarts4r) library(dplyr) I’ll start by loading the echarts4r and dplyr packages. Note I’m using the development version of echarts4r to access the latest version of the echarts JavaScript library. My houses_wide data frame has one column for Month (I’m just looking at December for each year starting in 2007) and columns for each city. If you want to follow along, data instructions are at the end of this article. Line charts with echarts4rįor example data, I downloaded and wrangled some housing price info by US city from Zillow. Next, you add a function for the type of chart ( e_line(), e_bar(), etc.) with the y-axis series column name as an argument.That takes your data frame and x-axis column as arguments. You start coding a visualization by creating an echarts object with the e_charts() function.Every function in the package starts with e_.Package author John Coene explains the basics in a getting started page:
