Using GoogleVis in R inside Power BI
As data analysis and visualization continue to grow in importance, the need for robust and efficient tools becomes increasingly critical. One such tool is Google Vis, a powerful library that allows users to create interactive visualizations using data from various sources. In this article, we will explore how to use GoogleVis in R inside Power BI.
Introduction to GoogleVis
GoogleVis is an R package that enables the creation of interactive charts and graphs using Google Charts. It provides an easy-to-use interface for users to create a wide range of visualizations, including bar charts, line charts, scatter plots, and more. One of the key benefits of Google Vis is its speed and efficiency, making it an ideal choice for large datasets.
Replicating Interactive Maps with R and Power BI
The original poster was trying to replicate an interactive map using R and Power BI. They had successfully created the map in R but were struggling to get it working in Power BI. After some research, they decided to replace Plotly with Google Vis due to its speed and efficiency.
Setting Up GoogleVis in R
To use GoogleVis in R, we need to install and load the necessary libraries. First, let’s install the required library using install.packages():
# Install GoogleVis
install.packages("googlevis")
Next, we can load the library using library():
# Load GoogleVis
library(googlevis)
Creating Interactive Charts with GoogleVis
Now that we have installed and loaded the necessary libraries, let’s create an interactive chart using GoogleVis. For this example, we will use a simple bar chart.
# Create a sample dataset
df <- data.frame(Values = 10, Project.Name = "Project A", Milestone = "Milestone 1")
# Convert date columns to Date type
df$Processed_start_date_cut <- as.Date(df$Processed_start_date_cut)
df$Processed_End_date <- as.Date(df$Processed_End_date)
# Create an interactive bar chart using GoogleVis
g <- gvisTimeline(data = df,
rowlabel = "Project.Name",
barlabel = "Milestone",
start = "Processed_start_date_cut",
end = "Processed_End_date",
options = list(timeline = "{rowLabelStyle:{fontName:'Helvetica', fontSize:10, color:'#603913'}",
barLabelStyle = "{fontName:'Garamond', fontSize:12}}",
backgroundColor = '#ffd',
height = 350))
Using GoogleVis in Power BI
Now that we have created an interactive chart using GoogleVis in R, let’s explore how to use it in Power BI.
Step 1: Create a New Report in Power BI
To create a new report in Power BI, follow these steps:
- Open Power BI and click on “Create” > “Report”.
- Select “Blank Report” as the template.
- Click on “Add data source” and select your R dataset.
Step 2: Create a New Visual
To create a new visual in Power BI, follow these steps:
- Drag and drop a new column from your dataset onto the “Values” section of the report canvas.
- Right-click on the column and select “Insert visual”.
- Select “Timeline” as the visual type.
Step 3: Configure the Timeline Visual
To configure the timeline visual, follow these steps:
- In the “Timeline” pane, click on the three dots next to “Data source” and select “Edit data source”.
- In the “Data source” tab, select your R dataset as the data source.
- Click on the “Options” button and select the following options:
- Row label: “Project.Name”
- Bar label: “Milestone”
- Start date: “Processed_start_date_cut”
- End date: “Processed_End_date”
- In the “Timeline” pane, click on the three dots next to “Options” and select “Edit timeline”.
- In the “Timeline” options tab, select the following options:
- Row label style: “{fontName:‘Helvetica’, fontSize:10, color:’#603913’}”
- Bar label style: “{fontName:‘Garamond’, fontSize:12}”
Step 4: Preview and Interact with the Visual
To preview and interact with the timeline visual, follow these steps:
- Click on the “Preview” button to preview the report.
- Click on the “Visual” tab to view the interactive timeline visual.
Common Issues and Solutions
The original poster reported several common issues while using GoogleVis in Power BI. Here are some solutions to these issues:
- Issue: The chart is slow and takes several minutes to compile. Solution: Replace
cat(g$html$chart, file="out.html")withprint(g, file="out.html"). - Issue: The chart disappears when the report is maximized. Solution: Make sure to add a refresh button or an F5 key equivalent to refresh the visual.
- Issue: The chart does not update when filters are changed. Solution: Use the
F5key or add a refresh button to update the visual.
Conclusion
In this article, we explored how to use GoogleVis in R and Power BI to create interactive charts and graphs. We also discussed common issues and solutions to these issues. By following the steps outlined in this article, you should be able to create interactive timeline visualizations using GoogleVis in both R and Power BI.
Last modified on 2023-07-04