Displaying 20 results from an estimated 10000 matches similar to: "two y-axis using ggplot"
2013 Apr 16
2
plot 2 y axis
Hi,
I want to plot two variables on the same graph but with two y axis just
like what you can do in Excel. I searched online that seems like you can
not achieve that in ggplot. So is there anyway I can do it in a nice way in
basic plot?
Suppose my data looks like this:
Weight Height Date
0.1 0.3 1
0.2 0.4 2
0.3 0.8 3
0.6 1
2023 Nov 24
1
ggplot adjust two y-axis
Hi Sibylle,
For that kind of data with two different scales, I generally use two graphs
that I name gg1 and gg2 and join them using gridExtra::grid.arrange(gg1,
gg2). This way, the red part of your graph is easier to interpret.
Have a nice day,
Charles-?douard
-----Message d'origine-----
De?: R-help <r-help-bounces at r-project.org> De la part de
sibylle.stoeckli at gmx.ch
Envoy??:
2023 Nov 24
1
ggplot adjust two y-axis
Dear R-users
Is it possible to adjust two y-axis in a ggplot differently?
- First y axis (0-60)
- Second y axis (0-2500)
### Figure 1
ggplot(Fig1,aes(BFF,Wert,fill=Studien_Flaeche))+
geom_bar(stat="identity",position='dodge')+
scale_y_continuous(name="First Axis", sec.axis=sec_axis(trans=~.*50,
name="Second Axis"))+
2023 Nov 24
1
ggplot adjust two y-axis
Hi,
I don't know the axis mecanism well enough in ggplot but using the original
barplot function you can add an axis on the right using the axis function.
Here is an example:
test <- as.table(matrix(c(2,10,3,11), 2,2))
barplot(test, beside = TRUE, col = scales::brewer_pal(palette = 1)(2))
axis(4, at = c(0, 5, 10), labels = c(0,50,100))
-----Message d'origine-----
De?:
2023 Nov 24
1
ggplot adjust two y-axis
Dear Charles-Edouard
Thanks a lot. Yes indeed barplot sounds excellent.
Unfortunately, the scale of the smaller axis is fixed, even If I am able to
draw to axes. The idea is to expand the scale to the scale to the second
axis for comparison.
F1 <- as.table(matrix(c(50,11,6,17,16,3,1,2237,611,403,240,280,0,0), 2,7))
barplot(F1, beside = TRUE, col = c("blue", "grey"))
2010 Nov 23
1
format y-axis values in ggplot
Hi,
I'd like to change scientific number formatting, 1,E+06, in y-axis values
to 1 000 000 (number with 1000 separator). How to do this in ggplot..? I
tried to use scale_discrete but couldn't get it to work. Below is a code I
have this far:
p<-ggplot(Data,aes(x=Date,y=PRINCIPAL))
p+geom_point()
Thanks for any help!
-Jack
[[alternative HTML version deleted]]
2017 Oct 12
0
dual y-axis for ggplot
Sorry let me clarify.
If I modify the line
p <- p + geom_line(aes(y = air_temp, colour = "Temperature"))
by
p <- p + geom_line(aes(y = air_temp, colour = "Temperature", linetype
="Temperature"))
and
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity"))
by
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity",
2017 Oct 12
2
dual y-axis for ggplot
Hi,
To my knowledge, an excellent of ggplot with a second y-axis is
https://rpubs.com/MarkusLoew/226759
In this example, the author uses two colors for the two lines, but the
line shapes are the same -- both are solid. Could each line have its own
color as well as its own shape? For example, can I make the red line with
the linetype "twodash", while the blue line with the
2023 Nov 24
1
ggplot adjust two y-axis
Hi,
Just find a scaling factor that would make the two sets of data comparable.
Here I divided the second row by 5 and did the same for the second axis.
Charles-?douard
F1 <- as.table(matrix(c(50,11,6,17,16,3,1,2237,611,403,240,280,0,0), 2,7))
barplot(F1, beside = TRUE, col = c("blue", "grey")) axis(2,
at=c(0,10,20,30,40,50,60, labels=c(0,10,20,30,40,50,60))) axis(4, at =
2017 Oct 12
1
dual y-axis for ggplot
Hi John,
You can try the following:
override.linetype=c("twodash","solid")
p <- ggplot(obs, aes(x = Timestamp))
p <- p + geom_line(aes(y = air_temp, colour = "Temperature", linetype
="Temperature"))
p <- p + geom_line(aes(y = rel_hum/5, colour = "Humidity",
linetype="Humidity"))
p <- p +
2013 Jun 15
2
Plotting two y-axis vs non-numeric x-axis
Hi dear all, the following code is correct. but I want to use non-numeric
x-axis, for example
if I replace time <- seq(0,72,6) by
month <-
c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Pag")
Ofcourse I use factor(month) instead of
2010 Dec 09
2
RES: Barplot with "Independent" Lines Y axis
Oh sorry. An example say lots more than words. The data below, when
submitted to twoord.plot return the mentioned error. Rain are bars and Salt
lines, the bars appear and the error occurs with the salt data.
Point Rain Salt
Fev/03 365.6 13
Mar/03 235 18
Abr/03 115.1 18
Mai/03 47.4 18.75
Jun/03 112 15
Jul/03 156.8 17
Ago/03 66.1 15
Set/03 149.8 14
Out/03 167,1 11.5
Nov/03 269.3 17.5
Dez/03 283.7
2011 Oct 31
1
Question on estimating standard errors with noisy signals using the quantreg package
Dear all,
My question might be more of a statistics question than a question on R,
although it's on how to apply the 'quantreg' package. Please accept my
apologies if you believe I am strongly misusing this list.
To be very brief, the problem is that I have data on only a random draw, not
all of doctors' patients. I am interested in the, say, median number of
patients of
2011 Jul 25
4
ggplot question: changing the label for the Y axis on a histogram
Some help with how to re-label the vertical axis in a histogram would be appreciated.
qplot(off.sc,weight=rel.freq,binwidth=.29,main="test Figure"+ylab("New from inside"))+ylab("New from outside")+
xlab("off.sc\nAggregated frequency plots for 17 equal intervals.")
The code
2012 Apr 26
2
How to plot graph with different scale (y axis) on same graph?
Hi,
I have my data in below format.
position var1 var2
2 .1 10
3 .29 89
12 .56 100
425 .34 1234
6546 .12 21
.... ..... .....
.... ..... ......
2013 Jan 08
1
ggplot not showing all the years on the x-axis
Dear R helpers,
I am currently having hard time fixing the values on the x-axis of a plot
with ggplot: even though I have 12 years, ggplot plots only 3 of them.
Here is my example:
library(ggplot2)
ii <- 2000:2011
ss <- rnorm(12,0,1)
pm <- data.frame(ii,ss)
tmpplot <- ggplot(pm, aes(x = ii, y = ss))
plot <- tmpplot + geom_line()
plot
In my case, ggplot reports on the year 2000,
2007 Nov 13
1
ggplot2: changing axis labels in ggplot()
Hi all,
For various reasons, I need to use ggplot instead of qplot for a complex
figure. Everything is working fine, except I cannot figure out how to rename
the axis labels in ggplot. I have pasted a simple example below. Any ideas
on what I am doing wrong?
Thanks for your help.
James
library(ggplot2)
##create data
2006 Oct 31
1
[ggplot] controlling axis and major/minor tick marks
Hello there!
I'm starting with ggplot and was wondering how I could control the axis
of a plot. I would like the axis of the plot to be drawn black which I
thought to acheive with the option axis.colour="black". However, this
had no real effect on the plot. Then I found grid.colour which I changed
to black as well. Now I got my axis as I wanted them, but ggplot now
draws the grid
2009 Oct 22
1
twoord.plot y lab size
I am using twoord.plot and my Y axis units on the left y overlap. I tried
using cex.axis in my par command but that only adjusted the x units, not the
y. cex.axis in twoord.plot did not help. How do I adjust Y units in the
twoord.plot?
example:
twoord.plot (lx=myear, ly=z, rx=myear, ry=sta,xlim=c(1985,2010),
xlab="Year",ylab="Individuals",
rylab="# Stations")
--
2012 Jan 03
4
Changing X axis of ggplot
Thanks to Joshua Wiley for turning me on to ggplot2.
I am making a plot using this:
p <- ggplot(dallas, aes(x = offense_hour)) + geom_bar() + coord_polar()
Dallas is a data frame, and offense_hour is a column with chron
objects from the chron library. In this case, the chron object was
created with the times function. It is only a time (H:M:S) with no
date attached.
The plot shows up fine,