Data source used for this post is the ‘Internet Sales’ data mart of the ‘AdventureWorksDW2017´ SQL server database.
In this example, we will look at plotting the yearly sales using a simple R script from the Power BI desktop. Let’s look at the steps involved in doing this.
1) Install R on your computer.
2) To enable R on your Power BI desktop app, select File->Options and settings -> Options and in the Options window select the ‘R scripting’ section to map the R installation directory. As a matter of fact, Power BI desktop detects the R installation folders and IDEs installed on your computer and shows them in the ‘R scripting’ section. Verify and update the correct R installation folder and click OK.

3) Click on the ‘R script visual’ in the visualizations pane. This step will add the R visualization on the reporting canvas and an R script editor below the visualization.

4) Add the ‘CalendarYear’ and ‘SalesAmount’ fields into the Values section of the visualization. This step will add a dataset in the R script editor.

5) By default, ‘Sales Amount’ is added as ‘Don’t Summarize’. Right-click on the SalesAmount on the Values section and select ‘Sum’.
6) Add the below two commands into the R script editor and click on ‘Run script’ to plot the yearly sales amount as a line graph.
names(dataset) <- c("Year", "Sales")
plot(dataset$Year,dataset$Sales,type="l",xlab = "Year",ylab = "Sales")

Hope this post helps you!