我想用x和y刻度绘制一个水平图作为log10刻度。
例如,我有一个像这样的正常水平图。
x <- 10*1:nrow(volcano)
y <- 10*1:ncol(volcano)
filled.contour(x, y, volcano, color = terrain.colors, plot.title = title(main = "Volcano topolgy", xlab = "Meters North", ylab = "Meters West"), plot.axes = { axis(1, seq(100, 800, by = 100)); axis(2, seq(100, 600, by = 100)) }, key.title = title(main = "Height\n(meters)"), key.axes = axis(4, seq(90, 190, by = 10)))
但是,x和y标度不是对数标度。我发现其他库“latticeExtra”具有日志刻度尺功能。例如,使用上面相同的x和y,我可以绘制日志刻度,但不能填充轮廓数据。
library(lattice)
library(latticeExtra)
xyplot(y ~ x, scales = list(x = list(log = 10), y = list(log = 10)), xscale.components = xscale.components.log10ticks, yscale.components = yscale.components.log10ticks)
如何使用日志刻度尺绘制水平图?我想稍后在水平图上绘制散点图作为日志位置。
提前致谢。
答案 0 :(得分:1)
如果您想继续使用x
,可以直接日志转换y
和axis
数据,并使用自定义base::plot
语句相应地调整轴,但它不是很优雅(log = "xy"
filled.contour
参数遗憾地在x <- log(10*1:nrow(volcano))
y <- log(10*1:ncol(volcano))
filled.contour(x, y, volcano, color = terrain.colors,
plot.title = title(main = "Volcano topolgy",
xlab = "Meters North",
ylab = "Meters West"),
plot.axes = { axis(1, at = log(seq(100, 800, by = 100)), labels = seq(100, 800, by = 100));
axis(2, at = log(seq(100, 600, by = 100)), labels = seq(100, 600, by = 100)) },
key.title = title(main = "Height\n(meters)"),
key.axes = axis(4, seq(90, 190, by = 10)))
中没有做任何事情:
ggplot2
您也可以尝试scale_y_log10()
scale_x_log10()
和<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main" >>>>>> X
app:menu="@menu/activity_main_drawer" >
<include
layout="@layout/nav_header_main"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.NavigationView>
对您有用,请参阅this question and answer。
答案 1 :(得分:1)
这是使用lattice
和latticeExtra
library(lattice)
library(latticeExtra)
xx <- 1:nrow(volcano)
yy <- 1:ncol(volcano)
levelplot(
x = volcano,
xlim = range(xx),
ylim = range(yy),
scales = list(x = list(log = 10), y = list(log = 10)),
xscale.components = xscale.components.log10ticks,
yscale.components = yscale.components.log10ticks
)