cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
jengwt Resolver I
Resolver I

Crate Bar Chart using R Visual

Hello, I am having some trouble using the R visual to create a bar chart. Yes, I know I could do it with the vanilla tool, but because of certain end user requests, I can't use it because it lacks certain aesthetics. So, I thought I would try using the R visualization.

 

I have a table with lots of transactional data, 'Monthly'. 7 of the columns in this table record the volumes made on a day-of-week basis; MON_VOL, TUE_VOl, .... FRI_VOL, SAT_VOL. I want the sums of each of these DOW volumes to be its own vertical bar, with a label pertaining to the DOW; "Mon", "Tue", ...

 

I also want the sums to be responsive to a date slicer. Will this be the case by default, since in theory only the data filtered by the data slicer should go to the R visual, or will I have to code that as well?

 

I know very little about R, so I would apprecite any help you can provide.

 

I did some googling when I thought of the idea, and this is what I have so far:

1) It looks like I'll have to tell R that each of those columns is a column (they're objects?).

            The main obstacle I'm having to getting started is that I keep getting the error: "object not found"

2) Then I'll have to have it sum each column.

3) Then I can actually create the barplot:

 

barplot(dataset, main="Day of Week Volume", 
   xlab="Day of Week")

 

The greyed out section of the code was provided by Power BI. These are some notes I had from a discussion with a friend who dabbles in R.

rbarplot.PNG

 

 

Addition: Getting a little closer now. Still not sure what's going on:

rbarplot2.PNG

4 REPLIES 4
Microsoft v-jiascu-msft
Microsoft

Re: Crate Bar Chart using R Visual

Hi @jengwt,

 

Try the demo in the attachment, please. The names aren't the legend in your expected result.

bar_names <- c("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN")
bar_height <- unlist(dataset[1, ])
barplot(dataset, main = "Day of Week Volumn", xlab = "Day of Week", height = bar_height, width = 3000, col = 'red', beside = FALSE, names.arg = bar_names)

create_bar_chart

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
jengwt Resolver I
Resolver I

Re: Crate Bar Chart using R Visual

@v-jiascu-msft Dale,

 

Thank you for the suggestion. However, using that code, I get the following result, which was very similar to one of the ones that I posted in the OP. Also, I notice that the data seems to be in ascending order, rather than by the order in which they were coded into the visual, or the labels. Is there a way to change this?

Capture.PNG

Microsoft v-jiascu-msft
Microsoft

Re: Crate Bar Chart using R Visual

Hi @jengwt,

 

Can you share your data? A dummy one is enough? It would also be great if you can share the expected result?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
jengwt Resolver I
Resolver I

Re: Crate Bar Chart using R Visual

@v-jiascu-msft No, a dummy chart will not work. The chart needs to update depending on the selections of the user.

Let me see what I can put together for you as far as dummy data.

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors
Top Kudoed Authors