Build a box plot using R

kabali

Banned User
Joined
Nov 30, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hi,

I need your help to create R code by creating Box plot. Click on the "this link" to get excel data sheet to create box plot using R code
this link

thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
See if this helps. You didn't say what you wanted to plot, so I just did visits vs. day of the week.
Also with Excel 365 you can do box plots without R.

When I imported your data to R I named it traffic (so you will need to change that part of the code to what ever name you used). I keep your headers the same as you had.
This line of code is just to put the DayofWeek on order for the graph.

traffic$DayOfWeek<-factor(traffic$DayOfWeek,levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))

For the box plot this would be the code.

boxplot(traffic$Visits~traffic$DayOfWeek,xlab="Day of Week",ylab="Visits")

1674761992405.png
 
Upvote 0
See if this helps. You didn't say what you wanted to plot, so I just did visits vs. day of the week.
Also with Excel 365 you can do box plots without R.

When I imported your data to R I named it traffic (so you will need to change that part of the code to what ever name you used). I keep your headers the same as you had.
This line of code is just to put the DayofWeek on order for the graph.

traffic$DayOfWeek<-factor(traffic$DayOfWeek,levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))

For the box plot this would be the code.

boxplot(traffic$Visits~traffic$DayOfWeek,xlab="Day of Week",ylab="Visits")

View attachment 83844
May I get the R code you used it to get the output please?
 
Upvote 0
I gave you the R code above, but here it is off the R console
I saved your Excel file as a Tab Delimited Text (txt) to import.
The choose() file in the read.table command will let you choose the file from were you saved it.


> traffic<-read.table(file.choose(),header=T,sep="\t")
> traffic$DayOfWeek<-factor(traffic$DayOfWeek,levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))
> boxplot(traffic$Visits~traffic$DayOfWeek,xlab="Day of Week",ylab="Visits")
 
Upvote 0
I gave you the R code above, but here it is off the R console
I saved your Excel file as a Tab Delimited Text (txt) to import.
The choose() file in the read.table command will let you choose the file from were you saved it.


> traffic<-read.table(file.choose(),header=T,sep="\t")
> traffic$DayOfWeek<-factor(traffic$DayOfWeek,levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))
> boxplot(traffic$Visits~traffic$DayOfWeek,xlab="Day of Week",ylab="Visits")
Pls show the r code and the output in Rstudio for me. Don't copy and paste the r code here
 
Upvote 0
I don't have an option to download it in Rstudio for you. The 3 lines of code above was copyed right out of R. All you have to do is copy and past the code above into R or just type it into Rstudio (it's only 3 lines of code).
Note I named the data as traffic, if you used a different name just change the traffic to what ever you named your data and skip the first line of code if the data is already in R.
If you look at post#2 above it shows the output of the boxplot command. Since you didn't say what you wanted a box plot to show I just picked visits and day of week.

1674942765635.png
 
Upvote 0
I don;t usually use Rstudio and the post above shows a screen shot of R.
Below if it helps is a screen shot of the same thing in Rstudio.

1674949148728.png
 
Upvote 0

Forum statistics

Threads
1,223,941
Messages
6,175,536
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top