0

Hi dear I have a little problem with a graphic in ggplot, I want to design a graphic that shows in x axis a varible that is a factor and in y axis the values of two continuous variables, to see the difference between first continuous and second variable related to the factor variable. The data frame is similar to this:

Group  Var1 Var2
1       10   20
2       15   30
3       5    10
4       20   15
5       5    5

My objective is to see the difference between var1 and var to in each member of factor. It is possible to make this in ggplot. Thanks a lot of.

1 Answer 1

3

Usualy, you should reshape your data in the long format to compare between variable. For example using melt from reshape2

library(reshape2)
dat.m <- melt(dat,id.vars='Group')

Then , for example, I am plotting here a geom_bar to compare between levels. Of course you can choose another geom.

library(ggplot2)
ggplot(dat.m)+
  geom_bar(aes(x=Group,y=value,fill=variable),
               stat='identity',position='dodge')

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.