As you go deeper into a container of water, the pressure increases, because the water at the top pushes down on the water below. A really deep "container" of water such as the ocean, for example, has MUCH higher pressure near the bottom than it does at the top.
The change in pressure with depth creates a buoyant force that pushes upwards on a vegetable or other floating object. The magnitude of this force is equal to the weight of water displaced by the vegetable.
The amount of water an object displaces depends on its volume -- the bigger it is, the more water it displaces. If the vegetable is less dense than water, the volume of water it displaces will weigh more than the vegetable does, so the buoyant force will be greater than the weight of the vegetable and it will float.
If the vegetable is more dense than water, by contrast, it will weigh more than the water it displaces, and the vegetable will sink. Density compared to water is what makes all the difference.
The density of any object is equal to its mass divided by its volume. If we weigh a vegetable to find its mass, then divide that mass by the amount of space the vegetable takes up, we know its average density.
The density of water is 1 gram per cubic centimeter at room temperature, so vegetables with densities above 1 gram per cc sink, while vegetables with densities below 1 gram per cc float.
Sometimes, people mistakenly assume that floating or sinking for vegetables is determined by weight. You'll know this is false, however, if you stop to think about a ship.
Ships are much heavier than rocks, but they float in water while a pebble sinks. Just as with the vegetables, the ship is less dense than the water while the rock is more dense than the water.