How to create bar graph from qualitative data in R? - r

I have two columns for olympic data showing the name of the team and one showing the type of medal won by the team. I am trying to calculate the number of medals won by each team in the olympics and then plot a bar graph from the data.
I do not know how to best go about it. The observations for teams repeat as they were extracted from a bigger data set as they show each participants nationality. I want to calculate for each team. However, there are mutiple teams and thus want to do it for the top 10 teams. I thus would also need assistance in ranking them.
Appreciation in this regard will be appreciated.

Related

Shiny choropleth map multiple indicators

I have seen many tutorials online, but I am not able so see the answer anywhere. I have a dataset with several indicators. Let's say I have a df with 947 observations (municipalities) with seven indicators (municipality id plus other municipality-level indicators). Some of these indicators are continous (for instance, the percentage of men in a municipality or the average age of people living in a municipality).
I also have a shapefile with the municipality boundaries. The sf file has also 947 observations and the same unique identifier.
I am trying to create a shiny app so that it displays a map for each of these seven indicators (displaying a choropleth map with the quantile distribution). In other words, the user should be able to select which indicator is displayed in the drop-down menu.
Do you know of any tutorial I could use? Any advice?

Best way to transform source data?

Working in R. But I think this question is universal.
Wall Street Journal visualized a dataset on disease infection rates in the U.S.:
X-axis is year. Y-axis is state.
And shade of red per tile is infection rate intensity for that particular state recorded for that year.
The source dataset being visualized is arranged as follows:
Each row in the dataset corresponds to a single infection rate for a single country in a given year. So, each red tile in the visualization corresponds to a row from the dataset.
But what if the dataset looked like this?:
Now, each row corresponds to a state. And each state/row has multiple infection rates, one for each year recorded. This might match how data is captured in the real world because for each year or day (in the case of coronavirus) you track the infection rate, you can just add a new column (rather than a 50 new rows).
The problem is while this layout is more human-friendly, it's not very R-friendly. We can easily create the tile visualization based on the source dataset arrangement where data is arranged by infection rate, but not so easily if it's arranged by state.
So, finally, my question is — is there an easy way to transform data from the second layout to the first, in Excel?
You can use the transpose function in the free, open-source OpenRefine tool to prepare your data file prior to loading it into R.

Multi-functional Shiny App Using Maps and Graphs

I am trying to develop a Shiny App in R for a project that I am working on in order to more efficiently share data and display results of this data for a large working group. I have a spreadsheet with 75 trailheads (points) that contain information related to latitude, longitude, and visitor usage data based on month and year starting in 2016. What I am hoping to do is develop an app that allows users to select all or multiple trailheads and either display the count numbers based on a selected month of a year or a year and have those results be displayed on a map as points based on density as well as a graphical plot that will display the results of the trailheads on a bar graph or something similar that users can look at the geographical dispersion of usage as well as usage trends.
I am have gone through many examples but cannot seem to find any that would allow all this functionality. If anyone can point me in the right direction, as far as locating code, that would be greatly appreciated.

Power View - Tables with columns of the similar data

Apologies in advance if my question is obvious but I'm new to this and having spent days searching and experimenting I cannot achieve the result I'm after.
I have a big table of data that I want to plot some graphs for, namely stacked columns and then filter these using other criteria such as date. I came across Power View and have been learning to use it hoping it will let me produce the reports I'm after rather than standard Excel graphs which are very clunky.
An example of the sort of data my tables contains is as follows although I have a lot of other columns and about 20 of the similar metric columns:
]
And this is the sort of graph I want to plot:
]
Where the red sections correspond to "R0" values, the orange "R1" and the green "R2" - they're essentially a rating; poor, ok and good. I can plot a single metric versus the items column with the stacked bar fine but cannot find a way to plot the metrics long the x axis for say a given item or sum of all items.
I've created measures using CALCULATE to filter by the rating but when I try and plot these my only option in power view is a clustered column graph where the x axis is the rating and the legend is the metrics.
I also created another small table with a single column of R0, R1 and R2 but can only link that to one metric column whereas I need it to link to all of them.
I think it's potentially a many to many mapping issue and have found a lot of links covering bridge tables and the magic CALCULATE function.
However as I'm trying to map values in a column to several other columns it doesn't seem to quite fit the many to many problem or if it does I can't see it.
I feel like what I'm after should be quite simple but I either end up with all my metric columns being made to show identical values or there's loads of cross filtering that I don't want. The "ratings" for each metric are essentially independent and I don't want to combine them in any way.
Any help is greatly appreciated and if my solution is in the links I've listed above then I'd really appreciate a bit of help with seeing it.
Thanks in advance

Pie charts in Qgis

I have this problem:
I would like to create a pie chart from a column of a attribute table, and I would like to see this pie chart above the map. The column contains names not nubers...
I work with marine species distribution data and I built a database of records of many many species...
In the specific, I have a column, called 'species', where there are many records (names) of some marine species. Several species may have many records, other species may have only a few numbers of records, so my objective is to graphically see the distribuition of records among the species.
If build a pie chart is a very time consuming procedure, I'd be happy to create a new column of the attribute table with the numbers of different species per year (see the attachments) or to try a totally new approach with R.
Thankyou for your help
img1 http://postimg.org/image/rn56c8l4z/
img2 http://postimg.org/image/e6918ynmj/
You'll most probably get many answers that pie charts are evil because they distort perception.
But along with better alternatives, namely stacked bar charts, you find code examples here
and, as always,
? pie
helps.
You may need to summarize your factor first, e.g. by table.

Resources