我试图理解为什么输出facet_grid()和输出facet_wrap()是不同的,即使输入是相同的:
ggplot(temp, aes(x = valor)) +
geom_histogram(binwidth = 5, fill = NA, color = "black") +
facet_grid(estratificacao ~ referencia, scales = "free") +
scale_x_continuous(breaks = seq(0, 100, 10)) + theme_classic()
Run Code Online (Sandbox Code Playgroud)
ggplot(temp, aes(x = valor)) +
geom_histogram(binwidth = 5, fill = NA, color = "black") +
facet_wrap(estratificacao ~ referencia, scales = "free") +
scale_x_continuous(breaks = seq(0, 100, 10)) + theme_classic()
Run Code Online (Sandbox Code Playgroud)
请参阅,该参数scales = "free"对于facet_grid()和没有相同的行为facet_wrap().有什么可以解释的?
(顺便问一下,还有另一个包可以做我想要的吗?)
这是我的数据集:
> head(df)
id groupID lat lon
511 1 277706 -10.89834 -37.05893
377 2 277706 -10.88870 -37.07695
98 3 277705 -10.89050 -37.09406
392 4 277697 -10.92131 -37.10525
6 5 277705 -10.89050 -37.09406
364 6 277697 -10.93730 -37.11600
Run Code Online (Sandbox Code Playgroud)
我想使用传单根据纬度和经度绘制地图上的每一行.另外,每个标记(或弹出窗口或CircleMarker)应该具有基于groupID变量的不同颜色和图层.
问题是数据每天都在变化,我不知道我将为groupID变量提供多少不同的唯一级别.在此示例数据集中有12个级别,但它可以在5到大约30之间.文档中的示例使用预定义的级别.
这是我尝试过的:
colorsmap = colors()[1:length(unique(df3$groupID))]
groupColors = colorFactor(palette = "RdYlBu", domain = df3$groupID)
leaflet(data = df3) %>%
addTiles() %>%
addCircleMarkers(lng = ~lon, lat = ~lat, color = ~groupColors(groupID),
group = ~groupID) %>%
#addLegend(position = "topright", pal = groupColors, values …Run Code Online (Sandbox Code Playgroud) 这是我的代码
import numpy as np
from numpy.random import randn
import pandas as pd
from scipy import stats
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
fig = sns.kdeplot(treze, shade=True, color=c1,cut =0, clip=(0,2000))
fig = sns.kdeplot(cjjardim, shade=True, color=c2,cut =0, clip=(0,2000))
fig.figure.suptitle("Plot", fontsize = 24)
plt.xlabel('Purchase amount', fontsize=18)
plt.ylabel('Distribution', fontsize=16)
Run Code Online (Sandbox Code Playgroud)
,结果如下:

我想做两件事:
1)通过将其值乘以10000来更改y轴的比例,如果可能,则为数字添加%符号.换句话说,我希望上图中显示的y轴值为0%,5%,10%,15%,20%,25%和30%.
2)向x轴添加更多值.我特别感兴趣的是以200的间隔显示数据.换句话说,我希望图中显示的x轴值为0,200,400,600,......等等.
我想将几个 ggplot2 图表组合成一个使用cowplot::plot_grid(). 从它的文档:
?plot
Arguments
...
List of plots to be arranged into the grid. The plots can be objects of one of the following classes: ggplot, recordedplot, gtable, or alternative can be a function creating a plot when called (see examples).
Run Code Online (Sandbox Code Playgroud)
所以,如果我输入一个 ggplot2 对象列表 plot_grid(),它应该将这些图合并为一个,对吗?
那么为什么这行不通呢?
p1 <- ggplot(mpg, aes(x = cty, y = hwy, colour = factor(cyl))) +
geom_point(size=2.5)
p2 <- ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() +
theme(axis.text.x = element_text(angle=70, vjust=0.5))
list(p1, …Run Code Online (Sandbox Code Playgroud) r ×3
ggplot2 ×2
cowplot ×1
facet-wrap ×1
leaflet ×1
matplotlib ×1
purrr ×1
python ×1
seaborn ×1