我想在我的 ggplot 中包含更详细的图例。当前的图例并不代表我所有的点尺寸。在以下示例中:
df <- "Freq Obs NumberOfWindows
15 0.5 40
12 0.4 80
10 0.3 100
8 0.2 800
6 0.18 1300
3 0.1 2000
1 0.05 30000"
ResA <- read.table(text=df, header=T)
library(ggplot2)
ggplot(ResA, aes(Freq, Obs, size=NumberOfWindows)) +
geom_point() +
xlab("Boundary frequency") +
ylab("Average number of overlaps per window (10kb)") +
ggtitle(as.character("The plot"))+
theme_bw()+
scale_size_continuous(name="area", range = c(1,20))
Run Code Online (Sandbox Code Playgroud)
请注意,我的数字范围从 40 到 30000。我在那里有很大的差异,但是,我希望在图例中至少有最大和最小的点。否则图例对小点没有多大帮助。这里的任何想法都受到高度赞赏。
这是我的代码(改编自此处):
\n\ndf_1 = pd.DataFrame({\'Cells\' : np.arange(0,100), \'Delta_7\' : np.random.rand(100,), \'Delta_10\' : np.random.rand(100,), \'Delta_14\' : np.random.rand(100,)}, columns = [\'Cells\',\'Delta_7\', \'Delta_10\', \'Delta_14\'])\n\n\n\n#figure\nfig, ax1 = plt.subplots()\nfig.set_size_inches(13, 10)\n\n\n\n#c sequence\nc = df_1[\'Delta_7\']\n\n#plot\n\nplt.scatter(np.full((len(df_1), 1), 1), df_1[\'Delta_7\'] , s = 50, c=c, cmap = \'viridis\')\nplt.scatter(np.full((len(df_1), 1), 2), df_1[\'Delta_10\'] , s = 50, c=c, cmap = \'viridis\')\nplt.scatter(np.full((len(df_1), 1), 3), df_1[\'Delta_14\'] , s = 50, c=c, cmap = \'viridis\')\ncbar = plt.colorbar()\nRun Code Online (Sandbox Code Playgroud)\n\n我想用 matplotlib 制作一个漂亮的抖动图(就像在R或seaborn上一样)。问题是我想根据每个单元格的“Delta_7”值给每个单元格一个颜色。当绘制“Delta_10”和“Delta_14”时,这种颜色将被保留,而我没有设法用seaborn做到这一点。\n如果您有任何线索(python包,编码),请告诉我技巧\xe2\x80\xa6)?
\n\n亲切地,
\nDataframe
df
Sample Type y1 y2 y3 y4
S1 H 1000 135 220 171
S2 H 2900 1560 890 194
S3 P 678 350 127 255
S4 P 179 510 154 275
Run Code Online (Sandbox Code Playgroud)
I want to plot y1, y2, y3, y4 vs Sample scatterplot with hue as Type.
Is there any way to do it in Seaborn?
我正在使用 ggplot 创建数据框的散点图。x 轴和 y 轴是框架中的两列,以下代码给出了散点图:
ggplot(df,aes(x=Season,y=type))+
geom_point(fill="blue")
Run Code Online (Sandbox Code Playgroud)
但这些点的大小都是相同的。我希望每个点取决于与 x 和 y 的组合匹配的行数。有人知道怎么做吗?
我想从 x 和 y 创建一个散点图,具有以下特征:
关于如何将这 3 个要求中的 2 个结合起来,我找到了很多答案。但是,我还没有看到它们全部联合实施,无论是在 seaborn 还是在 matplotlib 上。
scatter-plot ×5
python ×3
ggplot2 ×2
matplotlib ×2
r ×2
seaborn ×2
geom-point ×1
pandas ×1
relplot ×1