Nov 17, 2017 To visualize a small data set containing multiple categorical (or qualitative) variables, you can create either a bar plot, a balloon plot or a mosaic plot. For a large multivariate categorical data, you need specialized statistical techniques dedicated to categorical data analysis, such as simple. Top 50 ggplot2 Visualizations - The Master List (With Full R Code) What type of visualization to use for what sort of problem? This tutorial helps you choose the right type of chart for your specific objectives and how to implement it in R using ggplot2.
I've a list of protein names(P1,P2,...,Pn) and they are categorized to three different expression levels High(H), medium(M) and Low(L) as measured in three experimental conditions (Exp1,Exp2, and Exp3).
I wish to make a plot as shown in the bottom part of the figure, with the name of the proteins at the left and name of experiments along the top and high, medium and low categories are indicated by Red,blue and green respectively.
I'm new to R, I would much appreciate any help.
Thanks in advance
Andrie
140k2929 gold badges375375 silver badges446446 bronze badges
WoAWoA
2 Answers
You can create a file with data formatted like this (tab delimited):
And used the following commands to grab and plot them:
mat <- read.table(file.choose(),header=T)
# read the file into memoryattach(mat)
# map the header names to variable namesplot(pv~exp,col=val)
# plot the categories against each other and use val (H,M,L)
as the color array. R will assign those values to colors on its own. You can also create a color array using the val array to translate (H,M,L) to (Blue,Red,Green)... but there is other documentation out there for that.37.6k2323 gold badges114114 silver badges147147 bronze badges
DamianDamian
Here is an approach that uses some of the magic of the
ggplot2
and reshape2
packages.First, recreate the data in the format you described:
Next, load the add-on packages:
Then, use
melt()
to convert your data from wide format to tall format. The id variable is 'P', and we tell the function to rename the 'variable' to 'Exp':Because L - M - H has semantic order, we use the
ordered
parameter of factor()
to inform R of this order:Finally, we are ready to plot your data:
AndrieAndrie140k2929 gold badges375375 silver badges446446 bronze badges