R ggplot聚焦在一个轴上的区域和不同比例上 [英] R ggplot focusing in region and different scale in one axis

查看:39
本文介绍了R ggplot聚焦在一个轴上的区域和不同比例上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Google搜索,但是找不到解决我问题的答案.我有一些约会:

I googled but can't find an answer to my problem. I have some dates:

  • 温度日期(摄氏30至60克摄氏区域)
  • 以瓦特为单位的消费日期(区域为100到160瓦特)
  • 以GHz为频率的日期(1.2至3.1 GHz的区域)

然后,我将这些日期绘制在一张图形中,我看不到频率上的差异(它是如此之小).

Then I plot these dates in one graphic I cant see different in frequency (it so small).

如何在第0.1步和返回第10步后将1.2至3.1的轴刻度添加到轴上?

How add to axis ticks like 1.2 to 3.1 with step 0.1 and after return to step 10?

以及如何在1.2到3.1之类的区域中增加比例(步长是如此之大,我看不到10,步幅是如此之小),并在返回到步骤10的正常比例之后?

And how to add scale for region like 1.2 to 3.1 (it will be so big as step with 10 else I cant see. Step ticks it so small) and after return to scale normal for step 10 ?

我不会在轴的某些区域聚焦,也不会为聚焦区域添加一些比例.

I wont focusing in some regions of axis add some scale for focused region.

P.S.如果设置多轴,我可以在gnuplot中执行此操作,但我想在R中尝试.

P.S. I can do this in gnuplot if set multi axis but I want to try it in R.

P.S.P.S.对不起,英语

P.S. P.S. sorry for English

library(ggplot2)
s=matrix(0,10,4);
s[1:10,1]=1:10;
s[1:10,2]=1.2:3.1;
s[1:10,3]=70:79;
s[1:10,4]=150:159;
colnames(s) = c("time", "freq", "temp", "power");
ggplot(data=NULL, aes(x=s[,1], ) ) +
    geom_line( aes(y=s[,3], color="blue") )  +
    geom_line( aes(y=s[,4], color="red") )  +
    geom_line( aes(y=s[,2], color="green") ) +
    scale_y_continuous(breaks=c(1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,4,6,8,10) );

推荐答案

您数据的问题"是 freq temp & power 变量的标度非常不同.结果,当您将它们全部合并在一个图中时,几乎看不到尤其是 freq 变量的变化.此外,对于其他两个变量,随着时间的推移,很难看到其发展.

The 'problem' with your data is that the freq, temp & power variables have very different scales. As a result the variation in especially the freq variable can hardly be seen when you combine them all in one plot. Moreover, for the other two variables the development over time is hard to see as weel.

在这种情况下,使用多面图可能更明智:

In this case it's probably wiser to use a faceted plot:

# transforming the data into a dataframe of the long format
df <- as.data.frame(s)
require(reshape2)
df2 <- melt(df, id="time")

# creating the plot
ggplot(df2, aes(x=time, y=value, color=variable)) +
  geom_line() +
  facet_grid(variable ~., scales="free_y")

结果:

这篇关于R ggplot聚焦在一个轴上的区域和不同比例上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆